Help

Exit automation script before reaching the end

Solved
Jump to Solution
818 2
cancel
Showing results for 
Search instead for 
Did you mean: 
geophile
5 - Automation Enthusiast
5 - Automation Enthusiast

I am writing an automation script that takes an input X. I lookup X in a table, and then go on and do stuff with what I've found.

But if the lookup comes up empty, (no qualifying records), I want to exit the script. I could do this:

if (X was not found in table) {
    output.set("error", `${X} was not found`)
} else {
    // do stuff
}

But this gets messy. If I need to lookup X, and then Y, and then Z, then each additional lookup results in more indentation of my code. What I'd like to do is this:

if (X was not found in table) {
    return from script
}

"return" isn't allowed. Googling has not provided an answer.

Is there any way to do what I want?

1 Solution

Accepted Solutions
TheTimeSavingCo
17 - Neptune
17 - Neptune

No idea if this is the "Right" way, but you could just wrap everything in a function and do the return from there?

Screenshot 2022-12-22 at 12.57.59 PM.png

See Solution in Thread

2 Replies 2
TheTimeSavingCo
17 - Neptune
17 - Neptune

No idea if this is the "Right" way, but you could just wrap everything in a function and do the return from there?

Screenshot 2022-12-22 at 12.57.59 PM.png

geophile
5 - Automation Enthusiast
5 - Automation Enthusiast

Oh, right. Yes, that is perfect.