Need to cancel taks

abhisek
Tera Contributor

I have a requirement:

For a particular catalog item (for example: laptop), if the RITM state is closed skipped then I have to set the stage of

that RITM as cancelled and need to close all the relevant tasks (for exampl: X,Y and Z). In some cases some tasks also are having tasks (for example: the task X is having another tasks like A,B). I need to cancel those tasks as well.

 

Can anyone please help me out with the logic or implementation.

 

Thanks in advance.

 

Regards,

Abhisek Chattaraj.

2 REPLIES 2

Sohail Khilji
Kilo Patron
Kilo Patron

Dear @abhisek  ,

 

I belive you have 1 Request and 1 RITM for your catalog and having more than 1 catalog task for the same. In that case you can simply apply a after update business on sc_req_item table with condition as if <state is closed skipped> and  <item is 'xxxxxx'> etc..

 

And in advance business you can script to set the value of RITM to cancelled and gliderecord all the tasks associated with the current RITM and mark them closed.

 

Below script will help : (Adjust accordingly)

if (current.state == 'closed_skipped') {
      // Query related tasks (Modify the query according to your needs)
      var relatedTasks = new GlideRecord('sc_task');
      relatedTasks.addQuery('request_item', current.sys_id);
      relatedTasks.query();

      // Loop through related tasks and close them
      while (relatedTasks.next()) {
         relatedTasks.state = 'closed';
         relatedTasks.update();
      }
   }

 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @abhisek  

 

For a particular catalog item (for example: laptop), if the RITM state is closed skipped then I have to set the stage of

that RITM as cancelled and need to close all the relevant tasks (for exampl: X,Y and Z).

Atul: Do you have custom stage in your instance? Bcz OOTB cancel stage is not available.

LearnNGrowAtul_0-1703064402787.png

 

In some cases some tasks also are having tasks (for example: the task X is having another tasks like A,B). I need to cancel those tasks as well.

Atul: How you are managing task under task, I am sure it is again a customization. 

 

Are you updating the RITM directly ? which is not a good practice. As per process, you need to update the SCtask and then on basis of task the RITM get updated.

 

you want to do reverse in this case, which is not recommend. Also closed skipped means is the required activity is not required. 

 

Give a thought please. 

 

*************************************************************************************************************
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]

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