Run update business rule only if a field changes and not when the changes are made on entire record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 02:46 AM
Hi All,
I want to run an update business rule, only if a specific field changes and not when the changes are made on any other field in the record.
Here is my condition that I am using but it still runs the business rule if other fields are changed. Only once I want to run the update business rule and not often.
There is some concept on recursive (setWorkflow() ) in the best practice on how to use business rule, Not sure if this is the solution for my issue.
Business Rules Best Practices - ServiceNow Wiki
in condition i have put this : current.s_wf.changes()
(function executeRule(current, previous /*null when async*/) {
(function(){
var gr = new GlideAggregate('x_governa_pm_sl_s');
gr.addEncodedQuery('sp_name=Supplier^serv_monONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()');
gr.addAggregate('COUNT','sp_name');
gr.setGroup(false);
gr.query();
while(gr.next()){
var gr1 = gr.getAggregate('COUNT','sp_name');
gs.addInfoMessage(gr1 + 'GlideAgrregate Count');
var gr2 = new GlideRecord('x_governa_pm_sl_s');
gr2.addEncodedQuery('sp_name=Supplier^serv_monONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()^s_wf=6');
gr2.query();
if(gr2.getRowCount() > 0 && (gr2.getRowCount() > gr1*0.50 && gr2.getRowCount() < gr1*0.55) ){
gs.eventQueue("x_governa.Par_Submit_ISG_SUP",current);
gs.addInfoMessage(gr2.getRowCount() + " getrow count");
}
else if (gr1 == gr2.getRowCount()){
gs.addInfoMessage('full');
gs.eventQueue("x_governa.Full_Submit_ISG_SUP",current);
}
}
})();
})(current, previous);
Thanks in advance for your help. really appreciated.
Regards,
Narmi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 02:57 AM
Hi Narmi,
Could you try once by making the business rule before insert/update as compared now when it is running after update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 03:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2017 06:25 AM
Hi Dave,
I had specified the condition on Field 'changes' for after business rule but it still triggers the notification when I make changes to any other field for the record.
If I make the business rule to run on 'Before' as suggested by jaspalsingh it works fine and even it doesn't triggers the notification, when I make changes to any other fields of the record, However, it only triggers the partial notification (gs.eventQueue("x_governa.Par_Submit_ISG_SUP",current);) not the 'Full notification (gs.eventQueue("x_governa.Full_Submit_ISG_SUP",current);) even after matching both the conditions
Regards,
Narmi