Thursday, February 3, 2022

ServiceNow business rule to print the list of columns changed

For Global Scope Applications

 (function executeRule(current, previous /*null when async*/ ) {
    var gru = GlideScriptRecordUtil.get(current);
    var changedFields = gru.getChangedFields();
    var changedFieldNames = gru.getChangedFieldNames();

    //Convert to JavaScript Arrays
    gs.include('j2js');

    changedFields = j2js(changedFields);
    changedFieldNames = j2js(changedFieldNames);

    var arrayLength = changedFields.length;
    gs.log(arrayLength);


    for (var i = 0; i < arrayLength; i++) {
        gs.addErrorMessage(changedFields[i]);
    }

    var arrayLength1 = changedFieldNames.length;
    gs.log(arrayLength);

    for (var i = 0; i < arrayLength1; i++) {
        gs.addErrorMessage(changedFieldNames[i]);
    }
})(current, previous);

For Scoped application tables

 (function executeRule(current, previous /*null when async*/ ) {
    var result = [];
    var elements = current.getElements();
    var size = elements.length;
    for (var i = 0; i < size; i++) {
     var ge = elements[i];
     if (ge.changes()) {
      gs.addErrorMessage(ge.getName());
     }
    }
   })(current, previous);

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.