How to get List of RITM's records from Script Include

Supriya25
Tera Guru

Hi All,

 

Could you please help me how to get list of  RITM's records, which RITM has only All Closed Tasks
Conditions : 
1.RITM should have at least one Task record 
2.All  tasks should be closed ,no single task should be open state,
3.If any Task Open State, that RITM should not consider

Supriya25_0-1702672460840.png

 

IF we see there RITM0010002 tasks  all  are closed task, 
RITM0010001 has still open tasks. 

Only Which RITM of all Tasks closed that RITM numbers only should Return. (result should be RITM0010002)

 



1 ACCEPTED SOLUTION

Supriya25
Tera Guru
4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Supriya25 

 

Try this:

 

LearnNGrowAtul_0-1702665037893.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Supriya25_0-1702692321597.png

 

 

IF we see there RITM0010002 tasks  all  are closed task, 
RITM0010001 has still open tasks. 

Only Which RITM of all Tasks closed that RITM numbers only should Return. (result should be RITM0010002)

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @Supriya25 ,

Please find below background script, you can change script according to your requirements

var gr = new GlideAggregate('sc_task');
gr.addAggregate('COUNT','request_item');
gr.groupBy('request_item');
gr.addEncodedQuery('stateIN-5,1,2');     // state is one of open, pending, work in progress
gr.query();
gs.info(gr.getRowCount());
while(gr.next()){
    gs.info(gr.request_item.getDisplayValue() + "->"+gr.getAggregate('COUNT','request_item'));
}

 

Please mark my answer helpful & correct, it it helps you

Thank you

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Supriya25
Tera Guru