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

Business rule on Incident table running twice for insert and update

karthikbabu
Giga Expert

After Business rule on the incident table running twice.

find_real_file.png

Above is the Script causing an issue and below are the results. The result shows that it has two updates.

find_real_file.png

Is there a way to make this not happen twice?

1 ACCEPTED SOLUTION

Thanks for the update Karthik. if you need to update the value immediately after insert then you still go ahead with what you have. Just make sure to include the line current.setWorkflow(false); before current.update();



Note: You can prevent recursive Business Rules by using the setWorkflow() method with the false parameter, current.setWorkFlow(false). This will stop Business Rules and other related functions from running on this database access. The combination of the update() and setWorkflow() methods is only recommended in special circumstances where the normal before and after guidelines mentioned above do not meet your requirements.


View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Karthik,



You need to create a BEFORE business rule to update the current field and don't use current.update(); whereas an AFTER business rule is fine to insert records on target table.


https://developer.servicenow.com/app.do#!/document/content/app_store_doc_technical_best_practices_ja...


Thanks Pradeep for the immediate response.


Here is the scenario:


We have a custom field on Incident called u_add_time.


When a user tries to create an incident, he enters the mandatory fields and also the custom field(u_add_time) and submits the record.


Since the user enters value in to the custom field, a record needs to be created in target table and after record inserts in target table the custom field on the Incident table should be empty.



As per your suggestion I used two BR's for insert and update. It didn't worked.


After (insert,update)


find_real_file.png


Before (insert, update)


find_real_file.png


Thanks for the update Karthik. if you need to update the value immediately after insert then you still go ahead with what you have. Just make sure to include the line current.setWorkflow(false); before current.update();



Note: You can prevent recursive Business Rules by using the setWorkflow() method with the false parameter, current.setWorkFlow(false). This will stop Business Rules and other related functions from running on this database access. The combination of the update() and setWorkflow() methods is only recommended in special circumstances where the normal before and after guidelines mentioned above do not meet your requirements.


Thanks Pradeep. It worked. But while testing I found another issue. There is a field on the Incident table "sys_mod_count"(OOB field). When I first added the value in custom field (u_add_time) and save the record, the sys_mod_count shows one update. But when I update the value in the custom field and update the record the sys_mod_count shows as 3 updates. I am wondering what makes this update to become double?


find_real_file.png


find_real_file.png