Required Modification in Existing fix script of RITM Stages

thomas94
Tera Contributor

@Swathi Sarang 

 

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)

please refer below URL and guide me to add stages and approvals in existing script

Solved: To pick RITM which are in open state once after th... - ServiceNow Community

 

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());
6 REPLIES 6

swathisarang98
Giga Sage
Giga Sage

Hi @thomas94 ,

 

You can just update the encoded query as below,

 

gr.addEncodedQuery("stateIN-5,1,2^stageINfulfillment,waiting_for_approval^approval!=requested^ORapproval=");

 

swathisarang98_0-1711013464939.png

 

 

I have updated the script aswell,

 

var arr = [];
		var gr = new GlideRecord("sc_req_item");
		gr.addEncodedQuery("stateIN-5,1,2^stageINfulfillment,waiting_for_approval^approval!=requested^ORapproval="); // 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

Thank you for providing the script but unfortunately it is not giving the expected result , can you please provide the output of this script because for me it is not giving any output also if possible can you give the another script along with the expected result then it will be grateful for me, Thanks

 

Regards,

Vardan

@vardhan3 ,

 

Did you copy the the query from your instance ? as i have mentioned above ? if yes please share the script which you have used

 

Thanks 

Swathi 

vardhan3
Tera Contributor

Hi Swathi

Please check below script . it is not working currently but now I need the same which I have added in encoded query but instead of getting the approval field in query can you write a script like on approval table similar to sc_task ?

Kindly provide ASAP , It is urgent.

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

var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery("stateIN-5,1,2^stageNOT INRequest Cancelled,closed_incomplete,complete,closed_skipped^approval!=requested^ORapproval=");
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());
.......................................
Kindly provide the updated script.