logo

NJP

VaranExplains : Current and previous object in business rules

Import · Jan 25, 2023 · article

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

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 herevar 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 namessDebug += gru.getChangedFieldNames(); //Returns an arrayList of changed field elements with database namesgru.getChanges();

gs.log("Location afterBR=" + "preValue=" + preValue + " curValue="+ curValue + ' sdebug=' + sDebug,'vutil');

})(current, previous);

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%5Farticle%5Fview&sysparm%5Farticle=KB0553121

View original source

https://www.servicenow.com/community/now-platform-articles/varanexplains-current-and-previous-object-in-business-rules/ta-p/2457497