Fix Script

DEEPAK KUMAR SI
Tera Contributor

Hi Dev,s

Well it is quite silly question, but I am bit confuse

Statement is : Close all incidents which are have been opened for more than 3 months + not updated in past one month.

I have created the Fix script

----------------------------------------

var gr = new GlideRecord('incident');
gr.addEncodedQuery('stateNOT IN6,7^opened_atRELATIVELT@dayofweek@ago@90^sys_updated_onRELATIVELT@dayofweek@ago@30');
gr.query();
 
while(gr.next()) {
    gr.setValue('active', false);
    gr.setValue('state', 7);
    gr.work_notes = "This INCIDENT is being manually closed";
    gr.update();
}
------------------------------------------------------
I am confused with my Encoded query, can anyone clear 
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@DEEPAK KUMAR SI 

did you try to form the filter and copy the encoded query from there? it will be easier.

Also remember while closing you need to set close notes and close code then only it will allow update

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@DEEPAK KUMAR SI 

something like this

AnkurBawiskar_0-1700822424368.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Whatever Ankur has suggested is correct, however please use setWorkflow(false) in your code always.

var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^opened_atRELATIVELT@month@ahead@3^sys_updated_onRELATIVELT@dayofweek@ago@30');
gr.query();
 
while(gr.next()) {
    gr.setValue('active', false);
    gr.setValue('state', 7);
    gr.work_notes = "This INCIDENT is being manually closed";
gr.setWorkflow(false);
    gr.update();
}
Please hit like and mark my response as correct if that helps
Regards,
Musab