Business rule userId

marcos manzo
Kilo Contributor

Hello, i have a problem. I need to create a business rule, that create the userId, with the first letter of name + last name.

My script is working, but this create me to records and generate an error. 

I don't know, how eliminate this error.find_real_file.pngfind_real_file.pngfind_real_file.png

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi

your script includes the lines

var gr = new GlideRecord("sys_user");
gr.initialize()

and

gr.insert()

Skip them, replace "gr" with "current" and make sure, that your script is a "before" Business Rule.

Kind regards
Maik

View solution in original post

6 REPLIES 6

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi Marcos

In user table the userID is unique key. If you are going to create the two records with same user ID then it will give this error.

If you are generating any userID then update the record with that userID instead of inserting. Because it will try to insert record 2 times and will give you this error.

 

Thanks 

Gunjan


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

You can see that in your first 2 records, the 2nd record has userID but first record doesn't have any userID because of duplication.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

If you are writting the BR on before then don't write any update or insert statment and remove gr.initialize() from your script.

 

Thanks ,

Gunjan


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Maik Skoddow
Tera Patron
Tera Patron

Hi

your script includes the lines

var gr = new GlideRecord("sys_user");
gr.initialize()

and

gr.insert()

Skip them, replace "gr" with "current" and make sure, that your script is a "before" Business Rule.

Kind regards
Maik