- My View
Does the SetTimeout() function work in a business rule as it does in a client script? I know there are things that will/will not work between the two. Basically I need to add a delay within a business rule before I manipulate a field.
Thanks for the help.
mark.stanger, I also had a need for this in a custom application that we are building out.
I had a question about it though, that may seems like a crazy question, but I have to make sure.
only pauses the execution for the executing code, and NOT other code that is being executed, correct?
That depends on whether the other code is executing synchronously or not. Any code after the 'gs.sleep' command will wait for the full sleep to happen first unless it's in an async business rule I believe. Outside of that, it would be the 'order' field on a business rule for example that would control the synchronous ordering.
Maybe out of context, but we want to pause the notification script execution for some time. Do you think using gs.sleep() is a good idea in there?
Please let me know.
Please Hit ✅Correct, ⭐️Helpful, or ❣️Like depending on the impact of the response.
Thanks and Regards,
ServiceNow Solutions Architect
Parameter is in milliseconds. So gs.sleep(5000); will give you a 5-second pause.
I'm just curious - do you know why it is that you need to pause?
We have a business rule that, when it finishes/updates, triggers an outbound update to Omnibus. In that business rule, we are appending an "-x" to the correlation ID field in the incident to signify closed to Omnibus. Basically the "-X" causes the correlation ID to NOT match any inbound ID's from Omnibus, so we know to create a new incident.
We need the pause before the field update to allow the outbound message to be sent to Omnibus before the "-X" is added. If the "-X" is added before the update, then Omnibus is confused because the correlation ID doesn't match any that it has out there.
This is a very roundabout way to id, but due to the implementation of Omnibus in our environment, this is the way we are trying to do it.
I'm open to suggestions - I actually have another post asking if anyone can help me remove the "-X" in the outbound message before it send to Omnibus. I don't know enough about this piece of code to make that happen, so the only other way I could fiuyre to do it was to delay the field update until the message got sent.