execute() vs executeAsync() in Script Action

ColK
Tera Guru

To reduce waiting time for our users, I am making an API call via our MID server from a Script Action (I also need to process the returning body/message), but is there a difference between using execute()+setHttpTimeout vs executeAsync()+waitForResponse?

As I understand it, executeAsync is asynchronous, but waitForResponse forces it to act synchronously, and if the timer runs out for either setHttpTimeout or waitForResponse, an error will be thrown.

And please correct me if I'm wrong, but since this is all being run from a Script Action, there should be no impact on users if execute() was used versus executeAsync(). (Assuming I'm not making thousands of calls at once).

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Good documentation here: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0716391

But yes, execute and executeAsync is more so in regard to the action after the call is made, whether to wait for it or not. If that's all that's included in your script, then it firing async and processing async is fine, but some may want to wait for a response to move to the next block.

It doesn't necessarily mean because script action itself fires async, but more so the response from the call if you need it or not (right then or it doesn't matter to the rest of the script action).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

You're correct in your assumptions.

executeAsync was more of the guidance when making web service calls, etc. in situations where you had the choice to may it async versus sync.

If the situation is already async, then it's sort of redundant at that point.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Allen Andreas
Administrator
Administrator

Hi,

Good documentation here: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0716391

But yes, execute and executeAsync is more so in regard to the action after the call is made, whether to wait for it or not. If that's all that's included in your script, then it firing async and processing async is fine, but some may want to wait for a response to move to the next block.

It doesn't necessarily mean because script action itself fires async, but more so the response from the call if you need it or not (right then or it doesn't matter to the rest of the script action).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Got it! Thank you for the confirmation + clarification!