Business rule appears to be running twice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2013 11:44 AM
I am working on a business rule (on insert or change, executed before) that determines whether an Overtime/Time Off Request can be submitted based on the pay period covered in the Request and the current day's Pay Period information. The business rule is functioning correctly, but it appears to be executing twice. I have a log of gs.addInfoMessage statements still active for debug purposes and by their display I can trace the execution through the script twice.
Has anyone had this experience and is there something I could/should do to only execute the script once?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2014 08:26 AM
Hi,
yes,we should always use current.field.changes() along with current.field=="value" to ensure rule executes once.
For example first if we insert a request with value current.field=3(assuming numeric) ,rule will get triggered.Next lets say we or some standard business rule updates some field to x value,even now condition gets satisfied and the rule will get triggered.so its good to check whether the field has changed.
Alternatively we can use current.field.changesTo(value) instead of current.state.changes() && current.state == "value"
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2014 09:41 AM
Oh yes, this is a nice suggestion, thanks much JS!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 05:41 AM
Hi,
I'm facing the same issue my BR is running multiple times which contains gs.eventQueue(), resulting multiple notifications.
my condition is like below (its from day1 we created this BR)
(current.u_planned_start_date.changes()&& !current.u_planned_start_date.nil())|| (current.u_planned_end_date.changes()&& !current.u_planned_end_date.nil()) ||(current.state.changes()&& !current.state.nil())
but still it is getting triggered multiple times, are there any other factors which are reasons for this kind of issue.
Thanks,
Vamsi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2016 09:50 AM
Thank you for your input Felipe.
unfortunately the changesTo() or changes() do not work for async business rules.
http://wiki.servicenow.com/index.php?title=Business_Rules#When_Business_Rules_Run
Note: Asynchronous business rules do not have access to the previous version of a record. Therefore, these GlideElement methods do not work with async rules: changes(), changesTo(), changesFrom().
My pattern for an async business rule is now
(function executeRule(current, previous /*null when async*/ ) {
// can't use changesTo() because we're an async rule
// http://wiki.servicenow.com/index.php?title=Business_Rules#When_Business_Rules_Run
if (current.async_state == 'trigger_value') {
current.async_state = 'pending_value';
current.update();
// do some work here
current.async_state = ''; // we're done
current.update();
}
})(current, previous);
Hope this helps any other dev facing this issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2016 11:06 PM
Update
I still had my rule triggered twice occasionally.
So I updated my async business rule as follows
- check the trigger value in the condition rather than inside the script (best practice #7 ServiceNow KB: Best Practices — Business Rules (KB0540192) )
- use getValue instead of dot.walking
Condition
current.getValue('async_state') == 'trigger_value'
Script
(function executeRule(current, previous /*null when async*/ ) {
// enter the working state
current.async_state = 'pending_value';
current.update();
// do some work here
current.async_state = ''; // we're done
current.update();
})(current, previous);
Still wondering if I should enable glide.businessrule.async_condition_check or not:
To have the instance reevaluate the condition statement a second time before running an async business rule, add the system property glide.businessrule.async_condition_check and set the value to true.
Does anybody have experience on this property?