- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 02:04 AM
We have around 4lach inactive incidents which is not updated closed date and time stamp.
Planning to use back ground script to update the resolved date and time stamp to closed option as well. Is there any impact if we update all together in one shot ?
How we can analyse the impact if we perform in one go or any idea how we can proceed further. Need expert advise to take action to update for 4lach incidents.
Note: having below code to update the incident closed date and time currently.
var gr = new GlideRecord('incident');
gr.addEncodedQuery("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); (I will paste the query link which shows the incident list here.)
gr.query();
var count = 0;
while(gr.next()){
count++;
gr.closed_at=gr.resolved_at;
gr.update();
}
//gr.setWorkflow(false);
gs.print(count);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 02:11 AM
Hi,
Please do this
1) use fix script to update the records in background
2) also divide the fix script into chunks if possible
3) use setWorkflow(false) if you wish to avoid the BR from running on INC when INC is closed/resolved
4) also use try catch block to handle exception
5) wrap the code inside function
updateINC();
function updateINC(){
try{
var gr = new GlideRecord('incident');
gr.addEncodedQuery("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //(I will paste the query link which shows the incident list here.)
gr.query();
var count = 0;
while(gr.next()){
count++;
gr.closed_at=gr.resolved_at;
gr.setWorkflow(false);
gr.setUseEngines(false); // to prevent data policy from blocking the update
gr.update();
}
gs.info('Total INC updated' + count);
}
catch(ex){
gs.info('exception' + ex);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 02:11 AM
Hi,
Please do this
1) use fix script to update the records in background
2) also divide the fix script into chunks if possible
3) use setWorkflow(false) if you wish to avoid the BR from running on INC when INC is closed/resolved
4) also use try catch block to handle exception
5) wrap the code inside function
updateINC();
function updateINC(){
try{
var gr = new GlideRecord('incident');
gr.addEncodedQuery("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //(I will paste the query link which shows the incident list here.)
gr.query();
var count = 0;
while(gr.next()){
count++;
gr.closed_at=gr.resolved_at;
gr.setWorkflow(false);
gr.setUseEngines(false); // to prevent data policy from blocking the update
gr.update();
}
gs.info('Total INC updated' + count);
}
catch(ex){
gs.info('exception' + ex);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 06:30 AM
Hi Ankur,
Thanks for the above steps.
Is there any performance impact if we ran 4lachs incident update in single go ?, Please advise how we can proceed further.
Regards,
Nagaraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 06:40 AM
Hi,
please run it in non-business hours for less impact.
if possible please break the records in chunks and then run
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 06:41 AM
This article, using Ankur's code, will help you run this with no impact, and means you can run it during business hours too without causing any performance issues.