Background script to close the bulk RITM's .

Rashmi N
Tera Contributor

Hi,

 

I have a requirement to close the RITMs with condition below using background/fix script

1.Catalog item specific = 'xyz'

2.Assignment group is empty

3.State is open/work in progress/pending

 

I need to write a background script to close the RITMs which contain above condition, Let me know how to write the script for this, I tried some code but it's not working 

 

Thanks

Rashmi

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Try this

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item', '<sys_id of catalog item>');
ritm.addQuery('state', 'IN', '-5,1,2');
ritm.addNullQuery('assignment_group');
ritm.query();
while (ritm.next()) {
	ritm.state = 4;
	ritm.update();
}
-Anurag

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Try this

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item', '<sys_id of catalog item>');
ritm.addQuery('state', 'IN', '-5,1,2');
ritm.addNullQuery('assignment_group');
ritm.query();
while (ritm.next()) {
	ritm.state = 4;
	ritm.update();
}
-Anurag

Hi Anurag,

 

Thank you very much, I tried this script in my instance, it works for me.

 

Regards,

Rashmi

Uncle Rob
Kilo Patron

You can easily build that query in a list view.  Then copy the query.  Then do this...

//store your copy and pasted query you got from the list view.
var myQuery = 'pasted query you copied from list view'

//instantiate a gliderecord variable.
var ritmGR = new GlideRecord ('sc_req_item');
//verify that the query is valid.  SUPER important!
var validQueryCheck = ritmGR.isValidEncodedQuery(myQuery);

if (validQueryCheck){
   ritmGR.addEncodedQuery(myQuery);
   ritmGR.setValue('state',  4);
   ritmGR.updateMultiple();
}

 

 

Some videos if you want to know more about addEncodedQuery and also why its essential to verify queries

 

 

nikhil kamlekar
Tera Contributor

Hi @Rashmi N ,

 

It's better to go with the addEncodedQuery method in this case, because it has multiple conditions. Below is the working code to bulk close the RITM by building the query by forming the filter>run and copy query.

var reqVar=new GlideRecord('sc_req_item');
reqVar.addEncodedQuery('cat_item=060f3afa3731300054b6a3549dbe5d3e^assignment_groupISEMPTY^stateIN-5,1,2');
reqVar.query();
while(reqVar.next()){
    reqVar.state=3;
    reqVar.update();
}