- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2016 10:34 PM
I'm trying to update the short description on my request with the requested item's catalog item display value with an on after business rule. The script works and the short description is updated but I keep getting a message like Unique key violation detected by database (duplicate entry '81135af74f57124029de98701310c7a0' for key primary). I'm not sure why this message is appearing and what is relates to.
My business code like like the following
var request = new GlideRecord("sc_request");
var item = new GlideRecord("sc_cat_item");
request.get(current.request);
item.get(current.cat_item);
request.short_description = item.getDisplayValue();
request.update();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2016 12:08 AM
Hi Chris,
The error you are getting is a database error and it means that you are trying to do an insert for a sys_id that already exists. This usually happens if you have a before BR with current.update() which would trigger an insert already.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2016 11:24 PM
HI Chris,
Add gets in if condition and check if you have any before business rules with current.update().
var request = new GlideRecord("sc_request");
var item = new GlideRecord("sc_cat_item");
if(request.get(current.request)){
if(item.get(current.cat_item))
{
request.short_description = item.getDisplayValue();
request.update();
}
}
Mark this answer as helpful/correct if it does so
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2016 12:08 AM
Hi Chris,
The error you are getting is a database error and it means that you are trying to do an insert for a sys_id that already exists. This usually happens if you have a before BR with current.update() which would trigger an insert already.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2016 10:26 PM
Thanks Sergiu
What you described was exactly what was happening, my update() was inserting the record and else where code was running to insert the request record with the same sysid causing the message to appear.
I ended up using action tabs "set field values" to update the request record's short description this accomplished without causing that error message to appear to the user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2016 01:22 AM
hi,
Use setWorkflow(false) before update()