- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 06:52 AM
Hello,
I have a fix script that copies records from one table and inserts to another table. There are over 500,000 records being copied over. The fix script works fine, however, when I run the query it takes a very long time to run and will often timeout. In order for me to fully execute the fix script, I must run it several times. This is just a one off so we want to do this using a fix script. Below is the script I have written.
var gr = new GlideRecord('u_table_1');
gr.query();
while (gr.next()){
var gr1 = new GlideRecord('u_table_2');
gr1.addQuery('u_description',gr.u_description);
gr1.addQuery('u_short_description',gr.u_short_description);
gr1.addQuery('u_name',gr.u_name);
gr1.query();
if(gr1.next())
{
//do nothing
}
//if not found then insert
else{
gr1.initialize();
gr1.u_description = gr.u_description;
gr1.u_short_description = gr.u_short_description;
gr1.u_name= gr.u_name;
gr1.insert();
}
}
Is there maybe a way to segment the fix script so that it runs and completes much quicker?
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 11:18 AM
Try this.
var gr = new GlideRecord('u_table_1');
gr.query();
while (gr.next()){
var gr1 = new GlideRecord('u_table_2');
gr1.addQuery('u_description',gr.u_description);
gr1.addQuery('u_short_description',gr.u_short_description);
gr1.addQuery('u_name',gr.u_name);
gr1.setLimit(1);
gr1.query();
if(!gr1.hasNext()){
gr1.initialize();
gr1.u_description = gr.u_description;
gr1.u_short_description = gr.u_short_description;
gr1.u_name= gr.u_name;
gr1.setWorkflow(false); //stop execution of Business rule or other scripts.
gr1.insert();
}
}
If it stops in 5 mins then try running in background script then check logs if it throws any other issues. Also, can you confirm - both the tables are in same scope?
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 08:13 AM
You must choose to Proceed in Background as pointed by
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 08:21 AM
Proceeding in fix script in background does not make any issue.
I have deleted records for 2-3 days .
No one even sense it.
& about the approach i have already said simply run scheduled script after 15-20 minutes will work forsure.
Thanks
Sudhanshu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 08:43 AM
For long-running transactions like this, it is very wise to run in the background. Running on the foreground has an adverse effect on performance. Also, I believe if transaction stuck in the foreground the instance will get freeze and could affect all users.
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 08:45 AM
Agreed I does the same ran fix script using proceed in background option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 09:55 AM
I did use proceed in background when running the fix script. The script does not fully execute and needs to be ran several times in order for it to fully complete. Below is a screenshot of what I am getting. My team is currently advising against using a scheduled job, so I am trying to stay within the means of using a fix script.
This is the error that I am receiving: