Skip to main content

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?

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


Oh, right. Yes, that is perfect.


Reply