Business Rule Mass Update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2013 08:29 AM
Hey all,
Checking for any input on this one. I changed a business rule on Project that updates a field calculation. The rule executes when the form is saved but I'd like to update the existing records with the new calculation as well.
I found this post Mass update through script without calling Business Rules and Events that talks about running a simple background script and prevent things from running. So my question is, to get the business rules to trigger, could I just run it inverse as:
var gr = new GlideRecord('pm_project');
gr.query();
while (gr.next()){
gr.setWorkflow(true);
gr.update();
}
Or would I even need the setWorkflow bit?
Thanks,
-Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 05:57 PM
If you only want one business rule to run for all records, follow the pattern below:
var current = new GlideRecord('pm_project');
current.setWorkflow(false); //Do not run any other business rules following the update
current.query();
while (current.next()) {
//COPY BUSINESS RULE SCRIPT HERE
(function executeRule(current, previous /*null when async*/) {
})(current, previous);
//END BUSINESS RULE
// If before business rule
current.update();
}
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2019 03:44 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2019 03:58 PM
Hi Mike,
Try adding gr.autoSysFields(false) so no changes to system fields will be done
Cheers,
Joro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2019 04:12 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2019 04:21 PM
I use all of these when doing such things:
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.setForceUpdate(true);
If this is for single use - well defined condition ad no further bus. rules to be executed on this record its fine but if you need other BRs to run after that set gr.setWorkflow() to true ( gr.setWorkflow(true) ). Otherwise notifications, approvals, BRs, etc. stop being executed in the current context.