Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

VaranAwesomenow
Mega Sage

Symptoms

When using previous.field_name in after BR it in some cases doesnt respect field changes.

Diagnosis

In order to replicate the issue I have written a log statement to print current and previous value for a field such as name using same code looks like below.

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var sDebug = '';
var preValue = previous.name;
var curValue = current.name;

var gru = GlideScriptRecordUtil.get(current);
gru.getChangedFields(); //Returns an arrayList of changed field elements with friendly names
sDebug += gru.getChangedFieldNames(); //Returns an arrayList of changed field elements with database names
gru.getChanges();
gs.log("Location afterBR=" + "preValue=" + preValue + " curValue="+ curValue + ' sdebug=' + sDebug,'vutil');

})(current, previous);

 

Solution

Order of business rule should be <90 on cmn_location table in order for after business rule to track changes on a field.

VaranAwesomenow_0-1674666909862.png

 

Video Demo

 


 

References

https://servicenowguru.com/scripting/business-rules-scripting/checking-modified-fields-script/

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0553121

 

 

Version history
Last update:
‎01-25-2023 09:18 AM
Updated by:
Contributors