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.

complted tasks are also getting changed to closed incomplete if request is cancelled.

Debasis Pati
Tera Guru

Hello All,

I saw one scenario where if i cancel a request which has completed tasks and work in progress catalog tasks for all the tasks it makes as closed incomplete.
where i want it should not close incomplete the closed completed tasks it should only update the incomplete tasks(active true) to closed incomplete.

where is this oob behaviour present which makes this changes?

@Ankur Bawiskar  any suggestion on this?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Debasis Pati 

see if this OOTB BR does this "request closure"

Also you can try to enable debug business rule and see which BRs are triggering

AnkurBawiskar_0-1761570450045.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

23 REPLIES 23

Hello @Ankur Bawiskar ,
i tried the below but it's not updating the comment and work note

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here

   var comment = current.comments;
gs.info("Latest comment: " + comment);

// Update active Catalog Tasks
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request', current.sys_id);
taskGR.addQuery('active', true);
taskGR.query();
while (taskGR.next()) {
    gs.info("Updating task: " + taskGR.number);
    taskGR.work_notes= comment;
    taskGR.setValue('state', '4');
    taskGR.update();
}

// Update active RITMs
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('request', current.sys_id);
ritmGR.addEncodedQuery('active=true');
ritmGR.query();
while (ritmGR.next()) {
    gs.info("Updating RITM: " + ritmGR.number);
   
    ritmGR.comments = comment;
    ritmGR.setValue('stage', 'Request Cancelled');
    ritmGR.setValue('state', '4');
    ritmGR.update();
}



})(current, previous);

@Debasis Pati 

this line also to be updated to pick latest comment

var comment = current.comments.getJournalEntry(1); // picks latest comment

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar ,
Tried this but not working its not updating the comment and worknote

@Debasis Pati 

did you print what came in latest comment?

var comment = current.comments.getJournalEntry(1); // picks latest comment

gs.info('latest comment' + comment);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Yes @Ankur Bawiskar  ,
the below log came
Latest comment: 29-10-2025 17:29:30 - Debasis Pati (Additional comments)
test comment