- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 05:41 AM
Hi there!
I've created a BR in order to update a value from demand tablo to an enhancement table. It's a simple query and no much more...
but for some reason it runs very slow
the business rule is an 'after' type with a particular field change and it should modify a field in another table with the same value so:
(function executeRule(current, previous /*null when async*/) {
// it finds the related enhancement records
var udd = new GlideRecord('rm_enhancement');
udd.addQuery('enhancement', current.sys_id);
udd.query();
// set the due date with the same value
while (udd.next()) {
udd.u_due_date = current.requested_by;
udd.update();
}
})(current, previous);
I tested this BR in PDI and it works fast.
I used the field 'enhancement' because it is the reference field from demand table to enhancement table and because I couldn't find a reference demand field from the enhancement table.
any suggestion?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 07:19 AM
Keep the if condition and update the below query condition
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 08:42 AM
I would add a filter condition under "when to run" so your conditions are like Due date(requested by) changes AND Enhancement is not empty then update your script to something like this:
(function executeRule(current, previous /*null when async*/ ) {
// Get the referenced record from the enhancement field
var enhancementRecord = current.enhancement.getRefRecord();
// Check if the referenced record exists
if (enhancementRecord.isValidRecord()) {
// Update fields on the referenced record
enhancementRecord.due_date = current.requested_by;
enhancementRecord.update();
} else {
gs.error('Referenced enhancement record not found for sys_id: ' + current.enhancement);
}
})(current, previous);
Also, it's been a while since I looked at these but I think due_date.rm_enhancement is a Date/Time field while requested_by.dmn_demand is a Date field...so you may need to account for the type mismatch (all Date/Time values in ServiceNow are stored in UTC internally).