Unique Key violation detected by database error msg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 11:56 AM
//After business rule
//Insert
//Update
//Delete
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addActiveQuery();
gr.query();
var grReq = current.request_item.getRefRecord();
if (current.request_item) {
if (gr.next()) {
grReq.state = -10;
grReq.u_on_hold_reason = 'pending response';
grReq.update();
} else {
gs.eventQueue('createupdate.asAdmin', current);
}
}
})(current, previous);
Hello everyone.
This is the this AFTER business rule that causes the 'Unique Key violation detected by database' problem. I tried removing the.update() and changed it to a before business rule. Both do not work to resolve the error. What can I do to change the script? Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 09:20 PM
HI @tsoct ,
I trust you are doing great.
Please find the corrected code.
(function executeRule(current, previous /*null when async*/ ) {
// Check if current.request_item is not empty
if (current.request_item) {
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addActiveQuery();
gr.query();
var grReq = current.request_item.getRefRecord();
if (gr.next()) {
// Only update if the state or u_on_hold_reason has changed
if (grReq.state != -10 || grReq.u_on_hold_reason != 'pending response') {
grReq.state = -10;
grReq.u_on_hold_reason = 'pending response';
grReq.update();
}
} else {
gs.eventQueue('createupdate.asAdmin', current);
}
}
})(current, previous);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 09:46 PM
Thanks but i am still getting the same error
Unique Key violation detected by database ((conn=2179701) Duplicate entry 'aaf02f59876db110bcefdd383cbb35b5' for key 'PRIMARY')