- 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-06-2023 10:20 AM
Hi @Tom Siegel ,
Maybe I can suggest you a workaround. Not sure if this might help in solving your issues.
Is there any unique field available to identify? for example is "u_related_task" a unique field in that Table?
if yes then you can go to the table and mark this field as unique = true (unique field can be brought to list view).
This will act like a primary key and prevents adding a duplicate entry.
Mark helpful if it helps in solving your query.
Regards,
Johns
- 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-07-2023 12:02 PM
John - Yes I have confirmed this is the business rule causing the duplicatesby writing log messages to the sys_log that contain the action. I will however look into a Flow and report back.
Thanks,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 08:30 AM
John - Thanks again for your feedback. It doesn't appear that I can use a flow since they are async. I need the code to be triggered by a specific action on the Incident table.
Thanks again,
Tom