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

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello Ceraulo,

Yes this is possible.

Could you please let me know more deatils likewhen you want to show the message and things like that .

BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Nayan,

I have a UI Action that creates an incident record from an RITM.
What I want to do is created the incident record if there is only one catalog task and closed skipped the RITM.
If there are many catalog tasks and at least one is open, it will not create the incident record but will show a message that there is an open catalog task.
If there are many catalog tasks and all are closed, create the incident and closed skipped the RITM.

Thank you

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

@Mohith Devatte 

It works when there is only one catalog task.
It doesn't if there are more than one catalog task., The error message is not displayed.
Is there another way to do the update?

Thank you.