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.

Issue with Sequential Work Notes Updating in RITM Records

Aditi Jain
Tera Contributor

Hi Everyone, Need small help:

 

Hello everyone,

I am encountering an issue in ServiceNow regarding the work notes for RITM (Request Item) records. When I run my script to cancel requests, I observe the following behavior:

  1. Initially, the work notes are recorded separately, which is expected.
  2. After the state change activity, an additional work note is added that contains the concatenated messages.

 

Here is the script I am using:

 

 

var ritmArray = [
    "RITM0174132",
 "RITM0174127"
];
var count =0;
for(var i=0; i<ritmArray.length ; i++){
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('number',ritmArray[i]);
ritm.query();
if(ritm.next()){
    count++;
    ritm.stage = 'Request Cancelled' ;
 ritm.state = '4';
    ritm.work_notes = 'In an effort to maintain data quality within ServiceNow, any requests older than 2 months are cancelled.  Your request has met this criteria.  Please resubmit the request if still needed.  Thank you.';
    ritm.work_notes = 'Cancelling the ritm on request of INC1882708';
    ritm.update();
}
}
gs.print(count);

I would like to understand why the initial separate work notes are recorded first, followed by a concatenated entry after the state change. Is there a way to streamline this process to avoid redundancy in the work notes?

Any insights or recommendations would be greatly appreciated!

 

Thank you!

 

2 REPLIES 2

JenniferRah
Mega Sage
Mega Sage

Where is this code running? In a scheduled job? I'm honestly surprised you get anything other than 'Cancelling the ritm on request of INC1882708' in your work notes, based on this code.

I ran your code and got the same results. Very strange. When I consolidated your work_notes into one line, it seemed to work. My code:

var ritmArray = [
    "RITM0010014"
];
var count = 0;
for (var i = 0; i < ritmArray.length; i++) {
    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('number', ritmArray[i]);
    ritm.query();
    if (ritm.next()) {
        count++;
        ritm.stage = 'Request Cancelled';
        ritm.state = '4';
        ritm.work_notes = 'In an effort to maintain data quality within ServiceNow, any requests older than 2 months are cancelled. Your request has met this criteria. Please resubmit the request if still needed. Thank you.\n\nCancelling the ritm on request of INC1882708';
		ritm.update();
    }
}
gs.print(count);

 

JenniferRah_0-1745422286935.png