FIx script help to update closed time on incident table

RudhraKAM
Tera Guru

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 

find_real_file.png

 

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);
1 ACCEPTED SOLUTION

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

LinkedIn

View solution in original post

10 REPLIES 10

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

LinkedIn

var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("active=false^sys_updated_by=system^sys_updated_on>javascript:gs.dateGenerate('2018-12-13','23:59:59')");
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();
}

 

Can you please explain me what below lines of code are doing ?

 

grIncident._query();
while(grIncident._next())

Where do we check the resolved_at time ?

Ah did not see that one. Just change:

var newDate = GlideDateTime(grIncident.getValue('closed_at'));

Into:

var newDate = GlideDateTime(grIncident.getValue('resolved_at'));

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

LinkedIn

Can you please explain me what below lines of code are doing ?

 

grIncident._query();
while(grIncident._next())