- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 07:09 AM
Hello There
can some one help me with script to update closed date on incident table
We have a issue with BR which updated the close date of the incident same as resolved , for the data fix we need to write a fix script where it should update closed at of the incident with +3 days of resolved date
For example if the incident closed at and resolved at times are 1-1-2020 the fix is to set the closed at date to set as 1-4-2020
one issue is There are 200k incidents to update can some one help me with the optimised code
The query i used is
var gr = new GlideRecord('incident');
gr.addEncodedQuery("active=false^sys_updated_by=system^sys_updated_on>javascript:gs.dateGenerate('2018-12-13','23:59:59')");
gr.query();
var count = 0;
while(gr.next()){
count++;
gr.closed_at=gr.resolved_at +3 days;
gr.update();
}
gr.setWorkflow(false);
gs.print(count);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 08:19 AM
Example (= tested, obviously with different query for testing purpose) with the addDays.
var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery('sys_id=b0c8497edbd88cd0b9f39026db96195d');
grIncident.setWorkflow(false);
grIncident._query();
while(grIncident._next()) {
var newDate = GlideDateTime(grIncident.getValue('closed_at'));
newDate.addDays(3);
grIncident.setValue('closed_at', newDate);
grIncident.update();
}
Though, as mentioned, performing this 200.000 times is a bit worrying.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 09:25 AM
Same as regular query() and next(), just how I build my queries 🙂
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field