- 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 04:48 AM
Hi,
it is because of this part
if(count.next());
{
count.u_resolved = count.closed_at;
count.update();
}
}
You will need to change the if to a while
while(count.next());
{
count.u_resolved = count.closed_at;
count.update();
}
}
Thanks
Mark
if this has helped please mark as so, if this answered your question please mark as correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 05:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 05:10 AM
I tried with your script by changing table name and field name and it is working
can you please paste your scirpt:
doUpdate();
function doUpdate()
{
var count= new GlideRecord('incident');
count.addEncodedQuery('state=2^resolved_atISEMPTY');
count.setLimit(10);
count.query();
while(count.next());
{
count.work_notes = "Scrpt working";
count.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 05:11 AM
Hi,
I cannot see any reason why this would not be working.
maybe you can add a gs.print(count.sys_id) in the while loop and then look at the records that it has updated to see if it has done what you needed.
Thanks
Mark