Skip to main content
Solved

Exit automation script before reaching the end

  • December 21, 2022
  • 2 replies
  • 154 views

Forum|alt.badge.img+2
  • Participating Frequently
  • 5 replies

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?

Best answer by TheTimeSavingCo

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

2 replies

TheTimeSavingCo
Forum|alt.badge.img+31
  • Brainy
  • 6416 replies
  • Answer
  • December 22, 2022

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


Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • 5 replies
  • December 22, 2022

Oh, right. Yes, that is perfect.