- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 04:44 AM
Hi All,
I am trying to do Mass update on my Gb Case using background script.
Everytime when I run the script it updates only one record how can i do mass update on 80000 records?
below is the script.
doUpdate();
function doUpdate()
{
var count= new GlideRecord('u_gbs_case_management');
count.addEncodedQuery('state=5^u_resolvedISEMPTY');
count.setLimit(10);
count.query();
if(count.next());
{
count.u_resolved = count.closed_at;
count.update();
}
}
any advice would be helpful.
Thanks and regards,
Meenal
Solved! Go to Solution.
- Labels:
-
Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 04:57 AM
Hi Meenal,
Use setWorkflow(false) command. it will help you to execute the command smoothly.
please go through the link for more details:
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideRecord-setWorkFlow_Boolean
Run the code in below format:
doUpdate();
function doUpdate()
{
var count= new GlideRecord('u_gbs_case_management');
count.addEncodedQuery('state=5^u_resolvedISEMPTY');
count.setLimit(10);
count.query();
if(count.next());
{
count.setWorkflow(false);
count.u_resolved = count.closed_at;
count.update();
}
}
Hope this will resolve your issue. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 05:20 AM
Hi Mark,
After adding gs.print(count.sys_id) it gives me single sys_id on which the record is updated.
Thanks and regards,
Meenal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 05:24 AM
Can you check in the LIST view how record you are getting
navigate to u_gbs_case_management table in breadcrumbs pass the filter state & resolve and see how records you are getting.
Also check the row count in Script too:
doUpdate();
function doUpdate()
{
var count= new GlideRecord('u_gbs_case_management');
count.addEncodedQuery('state=5^u_resolvedISEMPTY');
count.setLimit(10);
count.query();
gs.print(count.getRowCount()); // Displays the number of records you are getting after quering the filter
while(count.next());
{
count.u_resolved = count.closed_at;
count.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 04:49 AM
Hello,
var count= new GlideRecord('u_gbs_case_management');
count.addEncodedQuery('state=5^u_resolvedISEMPTY');
count.setLimit(80000);
count.query();
while(count.next());
{
count.u_resolved = count.closed_at;
count.update();
}
}
Regards,
Sanket

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 04:50 AM
Replace If with while which Loops can execute a block of code as long as a specified condition is true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 04:50 AM
Mark ^ is correct and obviously you will also need to remove:
count.setLimit(10);
For such a large number of records not a bad idea to use set limit and run it as a few smaller jobs.
Some good practice Background Script tips here:
https://www.servicenowelite.com/blog/2017/8/25/code-vault/background-scripts
Regards
Paul