- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 04:14 AM
var grd = new GlideDateTime("2025-07-21");
grd.addDays(-30);
grd.query();
var gr = new GlideRecord("incident");
gr.addQuery('sys_updated_on','<',grd);
gr.query();
while(gr.next()){
if(gr.state!='7'){
gr.setValue('state','7');
gs.info(gr.number);
}
}
i write this code can anyone please help me to correct this code ?? as it worked but doesnot change the state to closed of some incidents IDK why?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 05:41 AM
Hi @harshchaudh ,
try this
var grd = new GlideDateTime("2025-07-21 00:00:00");
grd.addDays(-30);
grd.query();
var gr = new GlideRecord("incident");
gr.addQuery('sys_updated_on', '<', grd);
gr.query();
if (gr.next()) {
if (gr.state != '7') {
gr.setValue('state',7);
gr.setUseEngines(false);
gr.setWorkflow(false);
gr.update();
gs.info(gr.number);
}
}
why not use the Update JOB (no code approach)?
https://www.youtube.com/watch?v=5jZmZS6tb1I
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 04:35 AM
there is an OOTB data policy which blocks INC from update when State = 7
So you should set Resolution notes and Resolution code while updating
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
07-21-2025 04:46 AM
It didn't worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 08:29 PM
it should work.
please share what didn't work.
You mentioned it's not getting updated so I assumed your filter and query is fine
Remember closing incident requires those 2 fields to be updated and hence I updated those while updating the record.
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
07-21-2025 05:41 AM
Hi @harshchaudh ,
try this
var grd = new GlideDateTime("2025-07-21 00:00:00");
grd.addDays(-30);
grd.query();
var gr = new GlideRecord("incident");
gr.addQuery('sys_updated_on', '<', grd);
gr.query();
if (gr.next()) {
if (gr.state != '7') {
gr.setValue('state',7);
gr.setUseEngines(false);
gr.setWorkflow(false);
gr.update();
gs.info(gr.number);
}
}
why not use the Update JOB (no code approach)?
https://www.youtube.com/watch?v=5jZmZS6tb1I
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya