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 found this business rule earlier but SNC.Request i am not able to find what it is and where the closure script is written .

@Debasis Pati 

that script include is coming from platform level.

Did you deactivate that and see if it's not happening?

If it's not then that's the BR and you can keep it active=false and have your own logic.

💡 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

@Debasis Pati 

that BR is the culprit, I just verified this by deactivating it.

When REQ is Closed Cancelled, it moves RITM to "Closed Incomplete" and SC Task also

As mentioned earlier

-> keep that OOTB BR active=false and have your own logic in another after update BR on REQ

💡 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 ,
I also found that and deactivated and the below script i tried

(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.setValue('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.setValue('comments', comment);
    ritmGR.setValue('stage', 'Request Cancelled');
    ritmGR.setValue('state', '4');
    ritmGR.update();
}



})(current, previous);

It close incompletes the catalog tasks and requested items only one thing is not happening the comment is not gettting updated also thw work notes in sc_task table.



@Debasis Pati 

try these 3 lines and update them and also this one

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

taskGR.work_notes =  comment;

AND

ritmGR.comments = comment;

I believe I answered your original question on from where is that happening and what changes you will require.

💡 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