- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 05:40 AM
Hi All,
I am trying to update thousand record using background script. Script is working fine but it updates only one record instead of thousand. Please see the code in attachment and provide solutions, if anyone faced this type of issue.
Thanks,
Tara Singh
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:15 AM
Hi @Tarasingh26 ,
updateMultiple() doesn't work in scoped application, would suggest using standard update() function here, it should work just fine.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:16 AM
Hi @Tarasingh26 ,
updateMultiple() doesn't work in scoped application, would suggest using standard update() function here, it should work just fine.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 12:36 PM
Hi @Tarasingh26 ,
Hope you are doing great.
Instead of using update multipe use update function. also please try usig below script :
var gr = new GlideRecord("sn_risk_advanced_legal_entities");
gr.query();
while (gr.next()) {
var gr1 = new GlideRecord("cmn_cost_center");
gr1.addQuery('u_gl_company_code', gr.u_entity_code);
gr1.setLimit(100);
gr1.query();
while (gr1.next()) {
gr1.u_legal_entity = "ABC";
gr1.setWorkflow(false);
gr1.update();
}
}
Regards,
Riya Verma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 05:50 AM
Hi @Tarasingh26,
If you log your array you'll see that you are pushing 1 sys_id multiple times in your array.
Use arr.push(gr.getValue('u_entity_code')) instead.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 07:49 AM
Thanks Peter for you reply. It is updating now three records which not be the case. It should update atleast 300 records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 06:12 AM
Few recommendations from my side
1) always use scheduled job or fix script and don't use background script
2) wrap your code within function and use try catch block to handle exception
3) why to use array? why not directly use the next GlideRecord inside the while and no array is required
Please follow all the above points and your script should work fine.
If you face any issues please share the script here and not the screenshot
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 08:00 AM
Thank for reply. I have implemented with Glide record in while as well. Below is the script: -
var gr = new GlideRecord("sn_risk_advanced_legal_entities");
gr.query();
while(gr.next())
{
var gr1 = new GlideRecord("cmn_cost_center");
gr1.addQuery('u_gl_company_code', gr.u_entity_code);
gr1.setLimit(100);
gr1.query();
{
while(gr1.next())
{
gr.u_legal_entity="ABC";
gr1.setWorkFlow(false);
gr1.updateMultiple();
}
}
I checked with getRowCount. It should update about 48000 records but it is updating three records. What could be the reason. Where we need to make changes in script?
}
}