Auto Provisioning User - GlideRecord in Transform Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:22 AM
Hello experts
We have "Auto Provisioning User" enabled and an Azure Identity Provider synced with ServiceNow.
Now when a user logs in that does not exist in ServiceNow yet, a new user is automatically created. Here it is possible to make various queries in the transform script.
But if we now want to check if there is already a user with the same email address, the GlideRecord is not executed properly. My thought was that this is because the "Guest" user does not have permission for this query.
However, in the background script, if I now impersonate as guest and run the same query, the script runs as expected.
Does anyone know why this does not work in the onBefore transform script?
var isUserEmailUnique = true;
if (action == "insert") {
if (!source.email.nil()) {
var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', source.email.toString());
grUser.setLimit(1);
grUser.query();
if (grUser.hasNext()) {
isUserEmailUnique = false;
}
}
}
Thanks
Dominik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:34 AM
Hi,
Have you tried adding logs to print value of 'isUserEmailUnique'.
I see you have not set ignore=true in this script so that it should ignore the transformation.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 11:35 AM
Hi Anil
Thanks for your response. Sorry, I did not add the logs and ignore in this show script because I have some other queries after the gliderecord. But yes I tried it like this:
var isUserEmailUnique = true;
if (action == "insert") {
if (!source.email.nil()) {
var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', source.email.toString());
grUser.setLimit(1);
grUser.query();
if (grUser.hasNext()) {
gs.log("User Email is not unique");
isUserEmailUnique = false;
ignore = true;
}
}
}
Regards
Dominik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 03:07 PM
should not it be?
if (!source.u_email.nil()) {...}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 10:22 PM
Hi Nataliya
The field is a long complex string for us. For readability I have abbreviated it in the code example. I have already logged if something comes along and got the email adress back. So the field name should be right.
Thanks,
Dominik