Unique Key violation detected by database - Transform Map

Ayman Lhend1
Giga Guru

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.

AymanLhend1_0-1665403171262.png

N.B : user is a reference field to the system table sys_user

1 ACCEPTED SOLUTION

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.

View solution in original post

6 REPLIES 6

Throught usr.name i'm getting the name of the user in the sys_user table after querying via the second value of nonFormattedNameArray + its first value, the query is working just fine, and it fetches the right name, which means that everything is fine, but when i try to write to target.user i get that error.

Concerning the field map, i honestly have never used it, and i didn't even mention it in my script, so i doubt it's related in any way

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.