BR working only when current.update() is added
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 08:15 AM
HI,
I have quite a situation where, I have written an AFTER INSERT BR and it worked fine and updated records in san diego.. But when the same BR did not update records in UTAH, I added the current.update() and it started updating records.
(function executeRule(current, previous /*null when async*/) {
var usrarray = [];
var item = new GlideRecord('sc_req_item');
item.addQuery('request',current.sys_id);
item.addQuery('cat_item','57be3d29b7121010189e22b5de11a937');
item.query();
if(item.next()){
var almhw = new GlideRecord('alm_hardware');
almhw.addQuery('sys_id','IN',item.variables.assets.toString());
almhw.query();
while(almhw.next()){
usrarray.push(almhw.assigned_to.getDisplayValue());
}
current.short_description = "Hardware Asset Refresh Order for User(s) - " + usrarray;
}
})(current, previous);
Any specific reason?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2023 11:55 AM
@Swetha M I hope you have written this as Before Business rule.
Never write current.update() in any business rule.
try below for last lines
while(almhw.next()){
usrarray.push(almhw.assigned_to.getDisplayValue().toString());
}
current.short_description = "Hardware Asset Refresh Order for User(s) - " + usrarray.toString();
}
Bharath Chintala

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2023 06:24 AM
@Swetha M It seems you have written the business rule on sc_request table. There are few considerations that you can make :-
- For sc_request table, I would guess there is a workflow attached to it. In case there is, try changing the After Business Rule order to greater than 1000.
- For more information on the execution order of scripts and engines, try checking this link out
- Try implementing an Async business rule (On Insert) on the sc_req_item table with the condition
current.cat_item = 57be3d29b7121010189e22b5de11a937
Update the Request (sc_request) record Short description.
For more information on the getRefRecord() function, check the below link
https://servicenow.org.in/servicenow-tutotrial/getrefrecord-function-in-servicenow/
If this was helpful, please mark my answer as accepted solution, and give a thumb up.
Sayan Bardhan Roy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 08:18 PM
Hi @Swetha M ,
Although current.update() in BR is not a best practice you can use the same in the Async and after BR,
1) Use Async instead of after that gives instance more time.
or
2) Update the work flow or flow designer attached to it.
You got these two options too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 09:31 AM - edited 09-04-2023 09:34 AM
Hi Swetha,
Good day.
Using current.update() is not a best practise in Business rules. It can cause recursive issues.
I suggest you to create a Script Include and call the script Include from the Business rule.
Its very simple and follows the best practices.
new scriptIncludeName().myFunctionName();
//add this to the Business Rule.
//add this to your script include
myFunctionName : function(){
gs.info('Test');
},
If this was helpful, please mark my answer as accepted solution, and give a thumb up.
Regards
Vishnu P