
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 12:32 AM
Hi,
I am trying to use record producer on sys_user table to update fields like email/dob etc. But the record producer that I have created is not updating properly. Instead its creating a new record. Used this 'current.setAbortAction(true)' but this is not working. Instead getting an error message -> Error: Unique Key violation detected by database ((conn=11872) Duplicate entry '844b673e87d29d50fea1ebd73cbb35fe' for key 'user_name')
Can someone help me on this? Attaching below script which I used on Script section of Record producer.
var grUser = new GlideRecord('sys_user');
grUser.addEncodedQuery('sys_id=' + current.user_id);
grUser.query();
if(grUser.next()){
grUser.email= producer.email;
grUser.u_date_of_birth = producer.u_date_of_birth;
grUser.u_date_of_joining = producer.u_date_of_joining;
grUser.update();
gs.addInfoMessage('User record updated successfully');
current.setAbortAction(true);
}
Thanks in Advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 03:26 AM
I found it myself, I made a mistake on the query. It is supposed to be producer.user_id and not current.user_id
var grUser = new GlideRecord('sys_user');
grUser.addEncodedQuery('sys_id=' + producer.user_id);
grUser.query();
if(grUser.next()){
grUser.email= producer.email;
grUser.u_date_of_birth = producer.u_date_of_birth;
grUser.u_date_of_joining = producer.u_date_of_joining;
grUser.update();
gs.addInfoMessage('User record updated successfully');
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 12:42 AM
Hey,
Record producers per default will always create a record. I'd suggest you use a normal catalog item and execute the script in a flow instead. Then just auto-close the created request and requested item within the flow as well.
Regards
Fabian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 12:47 AM
Hi @Fabian Kunzke,
Here the expectation is to get data from Users and update them. We are not expecting any REQ & RITM to be created as they are unnecessary. Anyways thanks for your idea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 01:01 AM
Hi Sujitha,
Can you please recheck for the variable name in record producer. Are they starting with "u_"?
Regards,
Rahul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 01:10 AM
Hi @Rahul1,
Yes Rahul I am using custom fields. Since Date of Birth & Date of Joining as custom fields that I created in User table. And I have named them as the same, they start with "u_"