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.

RITM Closure and user notification

Swetham
Tera Contributor

Hello All,

 

I have a requirement to close out all the RITMs from a given list and the corresponding requests should also be set to the states and stages given in requirement

 

The requestor has to be notified with a close code comments stating " Your approval is rejected as it is long pending with the approver".

 

Below code is updating states and stages but comments is not getting updated.

 

@Anurag Tripathi Please advise.

 

try {
    var closeRITM = new GlideRecord('sc_req_item');
    // Adding encoded query to filterout records from list provided by incident management team to set state as close d incomplete.
//sample data
    var strQuery = 'number=RITM0003241';
    closeRITM.addEncodedQuery(strQuery);
   // closeRITM.setLimit(1);
    closeRITM.query(); 
    while(closeRITM.next()) {
closeRITM.setValue('work_notes',"Request is rejected following the three-strike principle, when pending approval for long time.");
closeRITM.setValue('comments',"Request is rejected following the three-strike principle, when pending approval for long time.");
       closeRITM.setValue('state',4);
closeRITM.setValue('stage','complete');
closeRITM.setValue('active','false');
       // closeRITM.autoSysFields(false);
       // closeRITM.setWorkflow(false);
  closeRITM.update();
 
 
var closeReq = new GlideRecord("sc_request");
closeReq.addQuery('sys_id',closeRITM.request);
closeReq.query();
if(closeReq.next())
{
closeReq.setValue('state',4);
closeReq.setValue('stage','closed_incomplete');
closeReq.work_notes = "Request is rejected following the three-strike principle, when pending approval for long time.";
}
       closeReq.update();
    }
}
 catch (e) {
    gs.error(gs.getMessage("Exception occurred while running fix job to close RITMs", e.message));
}
 
 

 

1 ACCEPTED SOLUTION

Hemanth M1
Giga Sage
Giga Sage

Hi @Swetham ,

 

Would you try dot walking update instead set value. 

//closeRITM.setValue('work_notes',"Request is rejected following the three-strike principle, when pending approval for long time.");
//closeRITM.setValue('comments',"Request is rejected following the three-strike principle, when pending approval for long time.");

//try below

closeRITM.comments = "Request is rejected following the three-strike principle, when pending approval for long time.";
closeRITM.work_notes="Request is rejected following the three-strike principle, when pending approval for long time."
       closeRITM.setValue('state',4);

 

tried in my PDI seems to be working 

HemanthM1_0-1694024052013.png

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

1 REPLY 1

Hemanth M1
Giga Sage
Giga Sage

Hi @Swetham ,

 

Would you try dot walking update instead set value. 

//closeRITM.setValue('work_notes',"Request is rejected following the three-strike principle, when pending approval for long time.");
//closeRITM.setValue('comments',"Request is rejected following the three-strike principle, when pending approval for long time.");

//try below

closeRITM.comments = "Request is rejected following the three-strike principle, when pending approval for long time.";
closeRITM.work_notes="Request is rejected following the three-strike principle, when pending approval for long time."
       closeRITM.setValue('state',4);

 

tried in my PDI seems to be working 

HemanthM1_0-1694024052013.png

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025