SCTASK is staying open when RITM is canceled in portal

PRADEEPREDDY GU
Tera Expert

Once RITM is created after that SCTASK is created with state is open, after that RITM is canceled by the requestor in Portal, SCTASK is still in OPEN state.

 

can anyone help me on this how to resole this issue.

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @PRADEEPREDDY GU 

It looks like you have a custom solution to cancel the request from the portal. You'll need to set the logic in your flow and update the state to "Closed Cancelled" or "Incomplete."

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Shivalika
Mega Sage

Hello @PRADEEPREDDY GU 

 

Is it working in native view ? I mean in system ? 

 

Well there's no OOB functionality for the same, but you can create below 👇 BR - 

 

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

    if (current.state == 4 && previous.state != 4) { // RITM is canceled

        var grTask = new GlideRecord("sc_task");

        grTask.addQuery("request_item", current.sys_id);

        grTask.addQuery("state", "!=7"); // Exclude already closed/canceled tasks

        grTask.query();

        

        while (grTask.next()) {

            grTask.state = 4; // Canceled state

            grTask.update();

        }

    }

})(current, previous);

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

PRADEEPREDDYGU_0-1743524060303.png

when to RUN Condition is correct?

Ankur Bawiskar
Tera Patron
Tera Patron

@PRADEEPREDDY GU 

You should have your own custom logic to handle this.

First of all Cancelled is not a OOB state value for RITM. Have you created a custom choice for this?

How are requesters cancelling the RITM? there itself you can add the logic

Also you can use custom business rule for this

BR will trigger when RITM is cancelled and will iterate all open tasks and close them

Condition: State [Changes To] Cancelled

Script:

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

    // Add your code here
    var taskRec = new GlideRecord('sc_task');
    taskRec.addActiveQuery();
    taskRec.addQuery('request_item', current.request_item);
    taskRec.setValue('state', 3);
    taskRec.updateMultiple();

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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