- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2022 09:46 AM
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.
Solved! Go to Solution.
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2022 10:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2022 10:03 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2022 10:06 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2022 10:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2022 10:04 AM
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