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

midde2
Giga Contributor

Thanks for the help Sagar:)

 

Regards,

Midde.

Vijaykumar2
Mega Expert

Please try with it.

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQueryQuery('cat_item=039c516237b1300054b6a3549dbe5dfc'); // place your query
gr.query();
while(gr.next())
{
gr.setValue('active','false');
gr.setWorkflow(false);
gr.update();
}

 

 

Thanks,

Vijaykumar