- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 05:03 AM
Hello,
I'm trying to do an import via a transform map that uses a script to properly import data
In this code below, i'm formatting fields of the column User so that it can fit the ServiceNow standards for Reference type fields (firstName lastName).
But unfortunately i always get the error "Unique Key violation detected by database ((conn=659) Duplicate entry 'bfc6fac0972611103f0f7b771153af05' for key 'PRIMARY')".
I do realize that a lot of people already posted about this error, but i just can't find a solution for my case in the forum, thank you.
N.B : user is a reference field to the system table sys_user
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2022 02:19 AM - edited ‎10-18-2022 02:20 AM
So after a lot of debugging and headache, i found where the error is coming from.
When i get the first element of the name via nonformattarr[0], somehow JS puts a space just before the beginning of the string, which messes up the whole thing and generates the error.
I just had to remove the space at the beginning of the string with String.trim().
Thank you so much for the help, really appreciate it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 07:22 AM - edited ‎10-10-2022 07:24 AM
I would suggest it's better to search the full name on user table and then pass the sys_id in target.user rather then display value , In the below example i am assuming ur getting first name in nonformattarr[0] and last name in nonformattarr[1], you can also break the query in first name and last name also but in below ex i have used full name
var nonformattname = source.u_user;
var nonformattarr = nonformattname.split(",");
var usr = new GlideRecord("sys_user");
usr.addQuery("name", nonformattarr[0] +" "+nonformattarr[1] );
usr.query();
if(usr.next())
target.user = usr.sys_id;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2022 02:24 AM
This does not generate any errors, but somehow the user field on the target gets populated with the non formatted value of the name (the one we got from source.u_user)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2022 02:29 AM
I've tried commenting out the part where you assign a value to target.user, and only get information about the user from the DB, but the error still persists
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2022 05:12 AM
what value you are getting in usr.name in the info message, Also make sure you have not created field map for the same field because you are setting the value of user via transform script.