current.update in Async business rule

DWARAM REDDY
Tera Contributor

i have total 40 async business rule. Those all business rules are in production. in those business rules we used the current.update() .Now the servicenow not alowing the current.update.

i want to replace the current.update and working thpose business rules properly.

What is the solution?

4 REPLIES 4

AnveshKumar M
Tera Sage
Tera Sage

Hi @DWARAM REDDY ,

To mitigate this issue, Create Script Include to handle the business logic (currently in async BR) and call the script include in async BR, you can also pass current and previous objects to the Script Include method if needed.

 

 

Thanks,
Anvesh

Thanks for the Reply .

in that case 40 script include are needed for calling  40 Async business rules right? suppose if the current.update() not required in business rule that time can i use the AbortAction()  .

@DWARAM REDDY 

I don't think abort action will do. Instead if you don't need current.update(), you can simply remove that line.

 

Regarding 40 script includes, you generalise the Script Inlcude to handle most common scenarios and reduce number of SIs required.

 

 

Thanks,
Anvesh

Rahul Kumar17
Tera Guru

Hi,

To replace the use of current.update(), you can use the gs.eventQueue API to queue an event that will update the record outside of the asynchronous Business Rule's execution context.

Here's an example of how you can replace the use of current.update() in an asynchronous Business Rule:

 

// Queue an event to update the current record
gs.eventQueue("record.update", current, current.getTableName(), current.sys_id);

 

In the above code, we use the gs.eventQueue API to queue an event of type "record.update" that will update the current record. The first argument is the type of event we want to queue, the second argument is the record we want to update, and the third and fourth arguments are the table name and sys_id of the record, respectively.

Note that the gs.eventQueue API is asynchronous, so the record will be updated outside of the asynchronous Business Rule's execution context. This means that you may not see the updated record immediately, but it will be updated eventually.

You will need to update all of your asynchronous Business Rules that use current.update() with this new code to avoid data inconsistency issues.

 

Thanks,

Rahul Kumar

 

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar