Why after update business rule not working where as before update business rule working, why?

KM SN
Tera Expert

i have defined a after update business rule  when state moved from resolved to I progress i want to assign same incident to one particular group and should clear assigned to value.

 

Its working if i kept before update but not working for after update ? why??

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

Looks like you are setting the value of a field in an after business rule for e.g.

current.assignment_group=<some group sys_id>;
current.assigned_to = '';

 

This works just fine if the script is used inside a before business rule as the fields get updated. However the same code doesn't work if you use it in the after business rule.

 

Here is the reason for this behaviour. According to ServiceNow documentation.

 

Before Business rule runs After the user submits the form but before any action is taken on the record in the database.
After Business rule runs After the user submits the form and after any action is taken on the record in the database.

 

Since the database operation already gets over before the control is passed to the after business rule. Hence changes made inside the after BR script do not get saved in database.

 

Solution: Use the following script to save your changes in after BR

current.assignment_group=<some group sys_id>;
current.assigned_to = '';
current.setWorkflow(false);
current.update()

 

Source: https://docs.servicenow.com/bundle/rome-application-development/page/script/business-rules/reference...

 

View solution in original post

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @KM SN,

Share your scripts here.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Sandeep Rajput
Tera Patron
Tera Patron

Looks like you are setting the value of a field in an after business rule for e.g.

current.assignment_group=<some group sys_id>;
current.assigned_to = '';

 

This works just fine if the script is used inside a before business rule as the fields get updated. However the same code doesn't work if you use it in the after business rule.

 

Here is the reason for this behaviour. According to ServiceNow documentation.

 

Before Business rule runs After the user submits the form but before any action is taken on the record in the database.
After Business rule runs After the user submits the form and after any action is taken on the record in the database.

 

Since the database operation already gets over before the control is passed to the after business rule. Hence changes made inside the after BR script do not get saved in database.

 

Solution: Use the following script to save your changes in after BR

current.assignment_group=<some group sys_id>;
current.assigned_to = '';
current.setWorkflow(false);
current.update()

 

Source: https://docs.servicenow.com/bundle/rome-application-development/page/script/business-rules/reference...