Fix script to update multiple records

RudhraKAM
Tera Guru

We have an issue when a request is create and if it has only one RITM and if the RITM is closed incomplete and set to active false but the parent request is still open and active true , We fixed the Bug but data need to be fixed , can some one help me with the script

find_real_file.png

8 REPLIES 8

Chaitanya Redd5
Tera Guru

Hi Kam,

You can use the below script:

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('state=4^active=false');
gr.setLimit(5);//this will update only 5 records only for testing purpose, please remove this line so that all the records will be updated at once
gr.query();
while(gr.next()){
	var gr2=new GlideRecord('sc_request');
	gr2.addActiveQuery();
	gr2.query();
	if(gr2.next()){
		gr2.setValue('state','value_of_state_you_want_to_set');//4 is the value for closed incomplete and 3 for complete
		gr2.update();
	}
}

remove setLimit piece of code to update the record at once.

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya

Thanks Chaitanya

 

How do we validate before we execute this ?  i mean instead of Update at first time how do print how many of there

Sorry provided you the wrong code, give me a moment and will update you with the correct one.

With the below script all the request which are active but all child RITM is in active false state will be changed to inactive and Closed Complete.

var gr=new GlideRecord('sc_request');
gr.addActiveQuery();
gr.query();
while(gr.next()){
	var gr2 = new GlideRecord('sc_req_item');
	gr2.addQuery('request',gr3.getUniqueValue());
	gr2.addActiveQuery();
	gr2.query();
	if(!gr2.next()){
		gr.setValue('state','3');//set the value as closed complete
		gr.setValue('request_state','closed_complete');
		gr.update();
	}
	
}