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
‎04-03-2013 08:42 AM
You don't need setWorkflow (you only need to use it if you want it to be false), but if you're not changing any values in your script you DO need to do the following, otherwise the update will be ignored:
gr.setForceUpdate(true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 05:22 PM
Thanks heaps @CapaJC - legend.
I needed to run my business rules on the sys_user table for all active records without actually updating the records. This worked perfectly (thanks to you!) and with very minimal system impact:
var gr = new GlideRecord('sys_user'); //call the sys_user table
gr.addQuery('active', 'true'); //only update active records
gr.query();
while(gr.next())
{
gr.update(); //make update changes - OF WHICH THERE ARE NONE
gr.setForceUpdate(true); //force the record to update even though no actual changes have been made
}
I dropped the above code into a scheduled job and it works perfectly. Cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2013 12:01 PM
Thanks for the input. We did some testing and this will work. In the tests I did, it updates between 2 and 3 records per second. Anyone know if this is this the most efficient method for updating tables?
Thanks!
-Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2013 12:38 PM
Well, doing it this way you're running ALL business rules on that table. If you only really want the one thing to happen, you could set workflow to false (so no business rules run), and just use your script to do the calculation of that field and update its value.