Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Work note validation and updation before setting in RITM

jobin1
Tera Expert

Hi All,

Before updating the RITM work note I need to check if the work note contains "ZjQcmQRYFpfptBannerEnd" and if so i need to eliminate this and pass it to RITM work note section how this can be handled?

Note: skip value logic is already working in the below script but I am unable to set the work note section with the trimmed content. also, it should not add twice I need to eliminate it and sent it only once to the work note section

tried the below before update business rule but not working

(function executeRule(current, previous /*null when async*/) {
 
var newWorkNote = current.work_notes.getJournalEntry(-1);
gs.log("wrknt1"+newWorkNote);
var skipvalue = 'ZjQcmQRYFpfptBannerEnd';
  if (newWorkNote.indexOf(skipvalue) !== -1) {
gs.log("wrknt2");
// Remove everything before skipvalue including skipvalue
        var index = newWorkNote.indexOf(skipvalue);
gs.log("wrknt3"+index);
        //current.newWorkNote = newWorkNote.substring(index + skipvalue.length).trim();
newWorkNote = newWorkNote.substring(index + skipvalue.length).trim();
  gs.log("wrknt4"+newWorkNote);
current.work_notes.setJournalEntry(-1, newWorkNote);
  gs.log("wrknt5");
}
 
})(current, previous);
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@jobin1 

what came in log and till which line it's working fine?

try this line

current.work_notes = newWorkNote;

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

jobin1
Tera Expert

current.work_notes if i use then also  old value will be available 
i need to apply the logic before passing to work note section