- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2024 05:53 AM - edited 02-24-2024 05:54 AM
I'm currently facing this issue in my ServiceNow instance. I have a Business Rule that successfully creates a work order from an incident. However, despite the creation of the work order, I'm consistently encountering the following error message.
Error Message: Unique Key violation deteceted by database ((conn=1035582) Duplicate entry '2fba04741b64c2504e3ba756
Here is the code I'm using to create work order from incident:
when to run condition : after insert and update
And also I have one more issue, When attempting to update an existing incident, the script should update the values in the respective work order. However, instead of updating the existing work order, a new work order is created, leading to data redundancy and potential confusion.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 04:02 AM
Hi i_sachin_,
Replace the logic with the following:
var WO = new GlideRecord('wm_order');
// check for exising record.
WO.addQuery('u_incident', 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.u_incident = 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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 04:02 AM
Hi i_sachin_,
Replace the logic with the following:
var WO = new GlideRecord('wm_order');
// check for exising record.
WO.addQuery('u_incident', 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.u_incident = 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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 06:42 AM
Hey @Bert_c1, thanks for your response. When I'm updating, the new incident is not being created, but I still get this error message:
Error Message: Unique Key violation detected by database ((conn=1130883) Duplicate entry '7fa18d421ba486607247a8e22a4bcb39' for key 'PRIMARY') while trying to create a new work order from the incident.
I have seen in other community posts that we have to remove the current.update() code in the business rule associated with the table, but I don't have any business rules like that. Can you help with this part?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 07:42 AM
Hey @Bert_c1, thanks for your response. When I'm updating, the new incident is not being created, but I still get this error message:
"Error Message: Unique Key violation detected by database ((conn=1130883) Duplicate entry '7fa18d421ba486607247a8e22a4bcb39' for key 'PRIMARY') while trying to create a new work order from the incident."
I have seen in other community posts that we have to remove the current.update() code in the business rule associated with the table, but I don't have any business rules like that. Can you help with this part.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 08:54 AM
Hey @Bert_c1 actually, the code you provided is working perfectly. When I first tried to run your code, I made a small mistake in the code, but now it's working. Thank you for your time!