Count catalog tasks in RITM

ceraulo
Mega Guru

Hello!

I have a requirement to check the catalog tasks created from an RITM.
If there is only one catalog task, do something.
If there is more than one catalog task and all are open, thrown an error message.
If there is more than one catalog task and are are closed, do something.

Is this possible?

Please help!

1 ACCEPTED SOLUTION

hello @ceraulo YOU CAN TRY THIS SCIRPT IN YOUR UI ACTION 

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.query();
if(gr.getRowCount()==1)
{
//write the code to create an incident record 
current.state=closed skipped state value;
current.update();
}
else if(gr.getRowCount()>1)
{
while(gr.next())
{
if(gr.state==open_state_value)
{
gs.addErrorMessage('There is a open catalog task');
current.setAbortAction(true);
}
else if(gr.state==close_state_value)
{
//write your code to insert the incident
current.state=closed skipped state value;
current.update();
}
}
}

Hope this helps 

Mark the answer correct if this helps you

View solution in original post

6 REPLIES 6

@Mohith Devatte 

This worked!
Thank you.

Maciej Kowalski
Kilo Expert

Hi, it is possible, you should try glide agregade

i leave you some some usefull links

https://developer.servicenow.com/blog.do?p=/post/glideaggregate/

https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/script/glide-server-apis/topic/p_GlideServerAPIs.html