Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

where and how to use "Async business rules"

Kishore8
Kilo Guru

How to use Async business rules, i don't know any thing bout it, plse help me

can please explain clearly.

10 REPLIES 10

Hi,



i would like to know ,


in which kind of situations we will use that, and where will we use that, how will we use that.


can you please provide code , for my understanding


There are plenty of OOB examples with code in the system.


Search for Business Rules where 'When' is "async".



I will provide one code example: Resolved all child incidents upon closure



When


Async



Update


True



Condition


current.active.changesTo('false');



Script


var incident = new GlideRecord("incident");


  incident.addActiveQuery();


  incident.addQuery("parent_incident", current.sys_id);


  incident.addQuery("incident_state", "!=", IncidentState.RESOLVED);


  incident.query();


  var msg = "";


  while (incident.next()) {


  gs.print("Incident " + incident.number + ' resolved based on resolution of Parent Incident ' + current.number);


  incident.incident_state = IncidentState.RESOLVED;


  if (incident.close_notes.nil()) {


  msg = "Close notes copied from Parent Incident";


  if (current.close_notes.toString().indexOf(msg) == 0)


  incident.close_notes = current.close_notes;


  else


  incident.close_notes = msg + ": " + current.close_notes;


  }


  incident.close_code = current.close_code;


  msg = "Resolved based on resolution of Parent Incident.";


  if (current.comments.toString().indexOf(msg) == 0)


  incident.comments = current.comments;


  else


  incident.comments = msg + " " + current.comments;


  incident.work_notes = current.work_notes;


  incident.update();


  }



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hi Paul, looking at the condition in the above BR it wouldn't work; since the 'previous' object is not accessible in an ASYNC BR, changes()/ changesTo()/ changesFrom() also wouldn't work...so if the script demands either of the above methods its better to change it to an AFTER business rule.



Cheers


Suhas


I see your logic there, but I all current methods work in async business rules (changes()/ changesTo()/ changesFrom()).


It is only previous that is not in scope.



I have tested myself with changes and changesFrom.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Ahh interesting. When I was going through some community threads on the same, found this one :



Why is the Condition Builder Hidden on async BR's?



So in a way it made sense as its ASYNC, it wouldn't have access to those 3 changes methods. Also this could be reason why you don't have access to 'Filter conditions' as S-Now had to change the choice-list fields to remove these methods 'changes/changesTo/changesFrom' from the drop down. (not much info regarding this in wiki or product doc)



But if it works, then I need to do some more work at my end to change the AFTER BR's to ASYNC



Cheers


Suhas