- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2023 06:57 AM
We have a business rule that is randomly creating duplicate records on a custom table.
The business rule is built over the Incident table.
When to Run: After Insert/Update, order = 1,000, Major Incident Changes to Proposed
Advanced:
(function executeRule(current, previous /*null when async*/ ) {
//gs.sleep(7000);
var canrec = new GlideRecord("u_incident_command_can_record");
canrec.addEncodedQuery('u_can_statusNOT INClosed,Cancelled');
canrec.addQuery('u_related_task', current.sys_id);
canrec.setLimit(1);
canrec.query();
gs.log("TSCAN - Active CAN Records: " + canrec.getRowCount() + " Incident Number: " + current.number);
if (!canrec.next()) {
canrec.initialize();
canrec.setValue("u_related_task", current.sys_id);
canrec.setValue("u_can_status", 'In Progress');
canrec.setValue("u_ic_eng", current.sys_updated_on);
canrec.setValue("u_impct_statement", current.short_description);
if (current.priority == 1); {
canrec.setValue("u_current_state", 'P1 Major');
}
if (current.priority == 2); {
canrec.setValue("u_current_state", 'P2 Major');
}
if (current.priority == 3); {
canrec.setValue("u_current_state", 'P3 Non-Major');
}
if (current.priority == 4); {
canrec.setValue("u_current_state", 'P4 Non-Major');
}
var sysID = canrec.insert();
}
gs.log("TSCAN - Creating CAN: " + current.number + " Action: " + current.operation()); //uncomment for debug
})(current, previous);
I worked with ServiceNow support and they pointed me to a slow running business rule firing at the same time as this one. I disabled the rule but was still able to reproduce 1 out of 10 times. I went as far as adding a glide query to make sure there was not an active CAN record associated with the Incident. Since the duplicates are happening at the same exact time, the glide query didn't return any records.
Any ideas would be appreciated.
Thanks,
Tom
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2023 02:51 PM
Hi,
Have you been able to confirm it's this business rule that is creating the duplicate record?
You could try using a Flow instead of a business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2023 08:16 AM
John - I was able to find some time to play arround with this, and allthough flows are async. When implemeted this did fire fast enough for my purposes and appears to have taken care of the duplicated record issue! Thanks again for your help