Async Business Rule for Insert

Community Alums
Not applicable

Hi All ,

I have a requirement for inserting records in custom table whenever there is a a new record created in Incident[incident] table .

I have tried writing Async business rules for "update" and its working as expected . But the same business rule is not working when I Use "Async" and "Insert" .

Will Async Business rule not work for "Insert" operation ?

Regards,

Ankitha

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi All ,



The script was running first and then the SLA was getting in created in task_sla table.Tried adding gs.SLEEP and it is collecting insertion data now.



Regards,


Ankitha


View solution in original post

5 REPLIES 5

sushant007
Kilo Guru

can you please share your script running in async BR?


Community Alums
Not applicable

Hi Sushant ,



PFB the below code



(function executeRule(current, previous /*null when async*/) {



        var task_sla = new GlideRecord('task_sla');


        task_sla.addQuery('task.number',current.number);


        task_sla.addActiveQuery();


        task_sla.query();


  while (task_sla.next()){


      var   metricdef = new GlideRecord('custom_table');


        metricdef.initialize();


        metricdef.setValue("u_table_name", "task_sla");


        metricdef.setValue("u_assignment_group",current.assignment_group );


        metricdef.setValue("u_priority",current.priority);


        metricdef.setValue("u_category",current.u_cs_category);


        metricdef.setValue("u_ci",current.cmdb_ci);


        metricdef.insert();


  }



})(current, previous);



Regards,


Ankitha


script looks good to me.


Can you please turn on the debugger and put some log statement in your script?


in this way we will come to know if your Async BR is getting executed or not ? if executed till what point it reached for insert in custom table.


benn23
ServiceNow Employee
ServiceNow Employee

I think the 2010 SLA engine uses an async business rule against task to create/update SLA records.   If that's the case, your script may not find the SLA because it hasn't been created yet.   Check out this property on your instance:   com.snc.sla.engine.version



You might try increasing the order of your Business Rule.   The above mentioned SLA runs at order 101 I believe, so yours would need to be > 101.