To pick RITM which are in open state once after the closure of child tasks.

vardhan3
Tera Contributor
 
1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @vardhan3 ,

 

Could you please elaborate your requirement ?

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

9 REPLIES 9

@vardhan3  i got it, could you please try below code let me know if this work or not ?

 

 

 

var arr = [];
		var gr = new GlideRecord("sc_req_item");
		gr.addEncodedQuery("state=1"); // state is open
		gr.query();
		while(gr.next()) {
			var closedCount = 0;
			var taskRec = new GlideRecord("sc_task");
			taskRec.addQuery("request_item", gr.sys_id);
			taskRec.query();
			var totalCount = taskRec.getRowCount();
			while(taskRec.next()){
				if(taskRec.active.toString() == 'false'){
					closedCount++;
				}
			}

			if(closedCount == totalCount && totalCount != 0){
				// if count is same then all tasks are closed then push RITM number in array
				arr.push(gr.getValue('number'));
			}
		}
		 gs.print(arr.toString());

 

 

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,

Swathi Sarang

Hi Swathi,

Can I get the same script for Stages of RITM.

@vardhan3 , as this thread is closed could you please raise a new question and tag me in that ?  and please explain the requirement in detail 

 

Thanks 

Swathi

Hi Swathi,

 

Actually i need modification in existing script only.

Requirement: In existing script need to add that if approval is requested then no need to pick up that RITM in list ,also required list of RITMs whose stages are Waiting for Approval (value 1)and fulfillment(value 2)

vardhan3
Tera Contributor

Hi Swathi,

Our requirement is we need the list of RITM numbers whose state is Open, WIP, Pending but all sc task should be closed. can you please provide the script?

I have prepared the below script but in the final array I haven't getting correct list of RITM Numbers.

.............................

var test = [];            
var test1 = [];            
var gr = new GlideRecord("sc_task");      
gr.addEncodedQuery("parent.active=true^active=false");      
gr.query();            
while (gr.next()) {            
if (gr.request_item.active ==true) {      
test.push(gr.request_item.number);      
}               
}               

gs.print("active RITM's with close complete SC tasks: "+test);

var gr1 = new GlideRecord("sc_task");      
gr1.addEncodedQuery("parent.active=true^active=true");                  
gr1.query();            
while (gr1.next()) {  
if(gr1.request_item.number!=""){          
test1.push(gr1.request_item.number);   
}   
}               
gs.print("RITM's with Open SC tasks: "+test1);   

test = test.filter(function(element) {      
return test1.indexOf(element) === -1;      
});               
gs.print("Final array: Open RITM with Closed SC Task " + test);