The CreatorCon Call for Content is officially open! Get started here.

current.update(); in script includes?

Bill Wulff1
Tera Expert

I am aware it is best practice to not call current.update(); in any business rules. Can we use current.update(); in script includes?

 

I have an ajax business rule where I am sending over data to a script include. I want to update the current record. Can I do so in the script include? I know it works, however, I do not know if it is recommended.

 

Thank you in advance.

1 ACCEPTED SOLUTION

Yes in that case.

We have similar integrations, where we run the integrations using script include and wait for the response and then do a current.update(); 

So you should definitely be able to use it. 

The recommendation to not use BR on onBefore, is because the record is saved anyway. If you call an update on onBefore, it will go in to a loop. And if you run a update on onAfter BR, it will again run the same BR and run a update again.

But since your job will be calling a script include and then an integration which will be asynchronous, you are fine to use current.update(). Or you can query the table with sysid and update as well.


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

Could you please explain the use case? Most of the time, the fields values can be set, before the record is saved.

So setting values in a Before Business rule would save the data you want to save.


Please mark this response as correct or helpful if it assisted you with your question.

I am utilizing the ECC queue application to call custom code on our mid server. I need to wait for the response to come back from the mid server before updating the current record. The business rule is my trigger to call the script include. The script include has logic to initialize a new ECC queue record, and then wait for the response from the mid server. I want to use an ajax business rule, so my user does not have to wait for script include to finish processing.

 

Let me know if that helps, or if you need more information.

Yes in that case.

We have similar integrations, where we run the integrations using script include and wait for the response and then do a current.update(); 

So you should definitely be able to use it. 

The recommendation to not use BR on onBefore, is because the record is saved anyway. If you call an update on onBefore, it will go in to a loop. And if you run a update on onAfter BR, it will again run the same BR and run a update again.

But since your job will be calling a script include and then an integration which will be asynchronous, you are fine to use current.update(). Or you can query the table with sysid and update as well.


Please mark this response as correct or helpful if it assisted you with your question.

Mr Everton
Tera Contributor

Hi Bill,

 

Not necessarily related to current.update() 
But also a good read about the use of "current" in Script Includes 🙂 

 

Can ServiceNow Script Includes Use the "current" Variable? - ServiceNow Developer Pro-Tips (snprotip...