How to access catalog task (sc_task) from sc_req_item script

sschleicher208
Kilo Contributor

I have a business rule on the "sc_req_item" table that is fired when any change is made.   Within that business rule, I'd like to access the catalog task(s) that sit beneath it (below the RITM).   Does anyone know how I would go about doing that from the business rule that fires on the sc_req_item?  

1 ACCEPTED SOLUTION

Brian Dailey1
Kilo Sage

Hi Stephen,



To grab all the Catalog Tasks that belong to a RITM, you can use the following in a server-side script such as a business rule:



ex.   BR on [sc_req_item]



var grTasks = new GlideRecord('sc_task');


grTasks.addQuery('parent', current.sys_id);


grTasks.query();


while(grTasks.next()){


//do something with the task record


grTasks.update();


}



Keep in mind that current is referring to your Requested Item.




Thanks,


-Brian


View solution in original post

4 REPLIES 4

Brian Dailey1
Kilo Sage

Hi Stephen,



To grab all the Catalog Tasks that belong to a RITM, you can use the following in a server-side script such as a business rule:



ex.   BR on [sc_req_item]



var grTasks = new GlideRecord('sc_task');


grTasks.addQuery('parent', current.sys_id);


grTasks.query();


while(grTasks.next()){


//do something with the task record


grTasks.update();


}



Keep in mind that current is referring to your Requested Item.




Thanks,


-Brian


By the way, forgot to mention... in the context of 'When' to run this Business Rule, you would probably want it running as either an After rule, since it is acting upon a different table and not making changes to the current record.



And as Abhinay commented, if you describe better what it is you are trying to accomplish, we can probably give you more detailed guidance.




-Brian


Abhinay Erra
Giga Sage

What are you trying to do here?


Geoffrey2
ServiceNow Employee
ServiceNow Employee

Brian is correct.   It's a basic GlideRecord. One of the most common scripts you'll ever write in ServiceNow. Read about it here: GlideRecord - ServiceNow Wiki