Get the catalog tasks of an RITM

ramya0905
Kilo Expert

Hi All,

Could you please help me to get all the task numbers generated under an RITM and check for a particualar assignment group for that task..

RITMxxxx

-TASKxxx1

-TASKxxx2

-TASKxxx3

How do i get this with the RITM's sys_id..

1 ACCEPTED SOLUTION

Hi Ramya,



Add new activity to your workflow - "Run Script" after finishing the the Task Creation.


And in the "Script" part of run script add the code as:


function getRec()


{


  var gr = new GlideRecord('sc_task');


  gr.addQuery('request_item',current.sys_id);


  gr.query();


  while(gr.next())


  {



    gs.log(gr.number);


  }


}



you will get all the tasks related to current RITM.



Thanks,


Ganesh


View solution in original post

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Ramya,



You can write the below script on Business rule. Please modify as per your requirement.


getRec();


function getRec()


{


  var gr = new GlideRecord('sc_task');


  gr.addQuery('request_item',current.sys_id);


  gr.query();


  while(gr.next())


  {


  gs.addInfoMessage(gr.number);


  }


}


NOTE: If you are using the before BR then don't use "current.update" in the BR.


function getRec()  


{  


  var gr = new GlideRecord('sc_task');  


  gr.addQuery('request_item',current.sys_id);  


  gr.query();  


  while(gr.next())  


  {  


// gs.addInfoMessage(gr.number);  


    gs.log(gr.number);


  }  


}



-------------------------


this one is in the final task of the RITM in the workflow's advanced script//


the log statement prints only the first task number and not the rest//


I just tried it on my instance and it works fine. Please find the attached screenshot for reference.


Screen Shot 2015-04-02 at 12.04.50 PM.JPG


this code works (y)



but if i have two tasks under one RITM..


RITM


-task0001


-task0002



and if the code is in the advanced script of the 2nd task's activity in the workflow, it logs only the task0001 and not task0002,


so what do i do to log the task0002 from task0002's workflow advanced script..?