Run update business rule only if a field changes and not when the changes are made on entire record

farci
Mega Expert

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

find_real_file.png

in condition i have put this : current.s_wf.changes()

find_real_file.png

(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

3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

Hi Narmi,



Could you try once by making the business rule before insert/update as compared now when it is running after update.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

Why not just use "when the specific field... changes" as a condition for that specific field?



find_real_file.png


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