Background script for making multiple requests to active False

midde2
Giga Contributor

Hi Everyone,

 

I have a code for making single requests to make active false by using Background scripts but for making multiple requests to make active false what i need to add in this below query.

 

Please suggest me on below code.

 

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', ##789);
gr.setLimit(1);
gr.query();
if(gr.next())
{
gr.setValue('active','false');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();

 

Thanks,

Midde.

1 ACCEPTED SOLUTION

SagarTajane
Kilo Expert

Hello ,

 

Please try this

 

var gr = new GlideRecord('sc_req_item'); 
gr.addEncodedQueryQuery('copy the query from filter'); 
gr.query(); 
while(gr.next()) 

gr.setValue('active','false'); 
gr.autoSysFields(false);
gr.setWorkflow(false); 
gr.update(); 
}

Example

 

var gr = new GlideRecord('sc_req_item'); 
gr.addEncodedQueryQuery('assigned_to=a8f98bb0eb32010045e1a5115206fe3a^active=true'); 
gr.query(); 
while(gr.next()) 

gr.setValue('active','false'); 
gr.autoSysFields(false);
gr.setWorkflow(false); 
gr.update(); 
}

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks
Sagar Tajane

View solution in original post

6 REPLIES 6

Shashikant Yada
Tera Guru

Try below code:

var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', ##789);
gr.setLimit(1);
gr.query();
while(gr.next())
{
gr.active = false;
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}

Dubz
Mega Sage
var gr = new GlideRecord('sc_req_item'); 
gr.addEncodedQuery('add encoded query here'); 
gr.query(); 
while(gr.next())   //use while to loop through the results
{ 
gr.setValue('active','false'); 
gr.autoSysFields(false);
gr.setWorkflow(false); 
gr.update(); 
} 

Jaspal Singh
Mega Patron
Mega Patron

Hi Midde,

 

Replace

gr.addQuery('number', ##789);  

with

gr.addEncodedQuery('pass_in_the_query');

& also remove gr.setLimit(1);

 

All you need is to apply necessary filter on RITM & then right click the filter end 

find_real_file.png

 

Then paste the query in the pass_in_the_query part.

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response. 

SagarTajane
Kilo Expert

Hello ,

 

Please try this

 

var gr = new GlideRecord('sc_req_item'); 
gr.addEncodedQueryQuery('copy the query from filter'); 
gr.query(); 
while(gr.next()) 

gr.setValue('active','false'); 
gr.autoSysFields(false);
gr.setWorkflow(false); 
gr.update(); 
}

Example

 

var gr = new GlideRecord('sc_req_item'); 
gr.addEncodedQueryQuery('assigned_to=a8f98bb0eb32010045e1a5115206fe3a^active=true'); 
gr.query(); 
while(gr.next()) 

gr.setValue('active','false'); 
gr.autoSysFields(false);
gr.setWorkflow(false); 
gr.update(); 
}

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks
Sagar Tajane