- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 03:23 PM
Is there a way to do bulk update other than this approach. This script works fine but i feel it might be causing performance issue.. Its one time update only.. But still would like to know what are the other alternative best practices, we have
var macRec=new GlideRecord('x_opt_macro_govern_macros');
macRec.addQuery('number','!=','');
macRec.query();
while(macRec.next()){
macRec.active='true';
macRec.update();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 03:24 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 11:11 AM
Just wanted to mention a word of warning for anyone reading this thread. When using updateMultiple(), it is critical to use the setValue() method and not to set field values directly. Per the documentation:
"When changing field values, use setValue() instead of directly setting the field (field = something). When using updateMultiple(), directly setting the field (gr. state = 4) results in all records in the table being updated instead of just the records returned by the query."
http://wiki.servicenow.com/index.php?title=Scoped_GlideRecord_API_Reference#updateMultiple.28.29
NOTE: Be very careful when using updateMultiple. You might unexpectedly update every record in your system!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 03:44 PM
Yes Kailash,
You can modify your code like below to use updatemultiple() method to improve performance.
- var macRec=new GlideRecord('x_opt_macro_govern_macros');
- macRec.addQuery('number','!=','');
- macRec.query();
- macRec.setValue('active',true);
- macRec.updateMultiple();
Regards,
Sachin