- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 10:39 AM
I need to update a new field on the sys_user table (37K records) . I tried a background script/fix script. Currently it's only running against my id and it's taking forever.
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', '213015900');
gr.query();
gs.print(gr.getRowCount());
while(gr.next) {
//gr.u_opt_in = true;
gr.setValue("u_opt_in", "true");
gr.setWorkflow(false); //Do not run business rules
gr.autoSysFields(false); //Do not update system fields
gr.update();
}
I have also tried 'Update All' and even for 1K records it timed out.
How is the safest most efficient way to update 1 field for all user records?
Solved! Go to Solution.
- Labels:
-
Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 10:42 AM
GlideMultipleUpdate is the most efficient way. I came across this blog entry a few years ago that helps explain its use:
Updating Multiple Entries | Glass 'putan with Service-Now
Because of its age it does use an old package call. Here is an out of the box example of its use with import sets when you click "reprocess". Make sure you use the new "GlideMultipleUpdate" API call instead.
var mu = new GlideMultipleUpdate("sys_import_set_row");
mu.addQuery("sys_import_set", current.sys_id);
mu.setValue("sys_import_state", "pending");
mu.execute();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2019 10:05 AM
@J.Moral, GlideMultipleUpdate's equivalent "addEncodedQuery" function is called addQueryString where you use that instead and pass an encoded query to it.
Regarding the failure and it will update the entire table, as noted in the GlideRecord article you can set glide.invalid_query.returns_no_rows system property to true to have queries with invalid encoded queries return no records.