Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Report of open RITMs with all closed tasks

Gmaster
Tera Contributor

Hello,

I have a question, how can I create a report (or list it via script) with all open RITMs (State == Open) but where all fulfillment tasks are closed? In other words when there is for example a request which has 5 tasks and all of them are closed but state of the request is Open, then I need that to show in my report.

Aby help much appreciated!

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @Gmaster ,

you can try this below script .

I tried this in Background script with the same scenario and it worked

var arr=[];
var gr= new GlideRecord('sc_req_item');
gr.addQuery('state',1);
gr.query();
while(gr.next())
{
var ct = new GlideRecord('sc_task');
ct.addQuery('parent',gr.sys_id);
ct.query();
while(ct.next())
{
if(ct.state==3||ct.state=="3")
{
if(arr.indexOf(gr.number.toString())==-1)
{
arr.push(gr.number.toString());
}
}
}
}
gs.print(arr);

Please mark my answer correct if it helps you

View solution in original post

9 REPLIES 9

Harish KM
Kilo Patron
Kilo Patron

Hi you can pull a report on SC_task table by dot walk to RITM, You will get both state values here

Regards
Harish

Hello,
Yes, but how can I check if all tasks assigned to RITM are closed on sc_task table?

Thank you!

Mohith Devatte
Tera Sage
Tera Sage

Hello @Gmaster ,

you can try this below script .

I tried this in Background script with the same scenario and it worked

var arr=[];
var gr= new GlideRecord('sc_req_item');
gr.addQuery('state',1);
gr.query();
while(gr.next())
{
var ct = new GlideRecord('sc_task');
ct.addQuery('parent',gr.sys_id);
ct.query();
while(ct.next())
{
if(ct.state==3||ct.state=="3")
{
if(arr.indexOf(gr.number.toString())==-1)
{
arr.push(gr.number.toString());
}
}
}
}
gs.print(arr);

Please mark my answer correct if it helps you

Thank you, this script works like a charm!