Auto Provisioning User - GlideRecord in Transform Script

Dominik9
Tera Guru

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

4 REPLIES 4

Anil Lande
Kilo Patron

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

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

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

should not it be?

 

if (!source.u_email.nil()) {...}

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