- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 11:45 PM
I had a requirement to copy a field on a Variable Set, to a new field on the RITM record. This is the Before Insert,Update BR i created
(function executeRule(current, previous /*null when async*/ ) {
//STRY0011219 - Update the Location value on RITM from the value selected on catalog item/requestor details variable set.
current.location = current.variables.location_address;
})(current, previous);
This seems to copy what i need. For reporting purposes, we need to copy this field for all historical RITM's
Is there a way I can run this BR as a background script?
I tried to use a force update background script, but i must be missing something here. The script seems to run, but when i go to the record, the field has not been updated.
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.setLimit(2);
ritmGR.setWorkflow(false);
ritmGR.autoSysFields(false);
ritmGR.addEncodedQuery('active=true^locationISEMPTY');
ritmGR.query();
while (ritmGR.next()) {
ritmGR.setForceUpdate(true);
ritmGR.update();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 11:59 PM
Hi Sample script:
gr = new GlideRecord('sc_req_item');
gr.addQuery('active','true');
gr.query();
while (gr.next()){
gr.location = gr.variables.location_address;
gr.setWorkflow(false); //Do not run business rules
gr.autoSysFields(false); //Do not update system field
gr.update();
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 11:59 PM
Hi Sample script:
gr = new GlideRecord('sc_req_item');
gr.addQuery('active','true');
gr.query();
while (gr.next()){
gr.location = gr.variables.location_address;
gr.setWorkflow(false); //Do not run business rules
gr.autoSysFields(false); //Do not update system field
gr.update();
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 11:48 AM
That got it, i did run this as a fix script once, and it stopped after about 14,000 records. Ran it again and it completed all the way.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 12:03 AM
Hi
Try the below code.
(function executeRule(current, previous /*null when async*/ ) {
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('active=true^locationISEMPTY');
ritmGR.query();
while (ritmGR.next()) {
ritmGR.variables.location_address = current.variables.location_address;
ritmGR.setWorkflow(false);
ritmGR.update();
}
})(current, previous);
Hope this helps you.
Thanks
