Unique Key violation detected by database ((conn=1167843) Duplicate entry 'de9299fa1ba88a504e3ba7562

Gowtham_22
Tera Contributor

Hi ServiceNow community,

I'm new to ServiceNow. Currently, I'm working on a requirement which involves creating an incident to work order and work order to work order task. I have written business rules for that. The incident to work order and work order task creation parts are working but with the error, after adding the work order to work order task creation business rule, I encountered the above error.

I've tried many approaches and also searched through many ServiceNow community posts, but I still haven't had any luck resolving this error. Can anyone help me with this?

Note: I don't have any business rule which involves current.update() and Additionally, there's another workflow running that creates work order to work order tasks. Do I need to deactivate that workflow to resolve this issue?

 

Incident to work order business rule:

(function executeRule(current, previous /*null when async*/) {

var WO = new GlideRecord('wm_order');
// check for existing record.
WO.addQuery('parent', current.number);
WO.query();
if (WO.next()) {
// update existing record
WO.caller = current.caller_id;
WO.location = current.location;
WO.priority = current.priority;
WO.state = current.state;
WO.assignment_group = current.assignment_group;
WO.assigned_to = current.assigned_to;
WO.short_description = current.short_description;
var WorkOrderID = WO.update();
} else {
// none found, so create new record.
WO.initialize();
WO.caller = current.caller_id;
WO.parent = current.number;
WO.location = current.location;
WO.priority = current.priority;
WO.state = current.state;
WO.assignment_group = current.assignment_group;
WO.assigned_to = current.assigned_to;
WO.short_description = current.short_description;
var WorkOrderID = WO.insert();
}

})(current, previous);

 

 

work order to work order task Business rule:

(function executeRule(current, previous /*null when async*/) {

var WOT = new GlideRecord('wm_task');
WOT.addQuery('parent', current.number);
WOT.query();
if (WOT.next()) {
WOT.u_work_order_type = current.u_work_order_type;
WOT.u_caller = current.caller;
WOT.location = current.location;
WOT.state = current.state;
WOT.assignment_group = current.assignment_group;
WOT.short_description = current.short_description;
var WorkOrderTaskID = WOT.update();
} else {
WOT.initialize();
WOT.parent = current.number;
WOT.u_caller = current.caller;
WOT.u_work_order_type = current.u_work_order_type;
WOT.location = current.location;
WOT.state = current.state;
WOT.assignment_group = current.assignment_group;
WOT.short_description = current.short_description;
var WorkOrderTaskID = WOT.insert();
}

})(current, previous);

Both business rule when to run conditions are after inser and update

Could someone please review the content above and provide assistance?"

0 REPLIES 0