Fix Script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2023 02:30 AM
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
----------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2023 02:37 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2023 02:40 AM
something like this
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2023 03:38 AM
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();
}
Regards,
Musab