How to auto close changes older than 30 days

Carol2
Tera Contributor

Hi, please assist with the below script. 

I tried the below code it closes changes that are new. I want to close changes that are in 'scheduled' ,'implement' and 'review' state where the planned implementation date is older than 30 days and the related
Task should be closed as well.

var gr = new GlideRecord('change_request');
gr.addQuery('u_change_phase', 3);
gr.addQuery('active', true);
gr.addQuery('opened_at', '>', gs.daysAgoStart(30));
gr.query();
while (gr.next()) {
gr.u_change_phase = 4;
gr.change_state = 5;
gr.active = false;
gr.update();
}

6 REPLIES 6

Carol2
Tera Contributor

I initially tested with 'u_change_phase' = 0, and it worked it updated all new changes but when i updated the state that i wanted it didn't work. i'm testing the changes first to see if that works.

So can you double check what I mentioned:
change_state

Is this a correct field?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn