Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

User Criteria script to restrict 'Available for' on Record Producer to use field value

SNAdmin47
Kilo Sage

I'm trying to get a record producer on our portal to only be visible to certain users according to a new field on the user form, which is 'u_authorised'. I'm trying to do this via the 'Available for' list on the record producer and have created a new user_criteria record which is using the below script in the advanced script option of the user_criteria record. I've tried a few different variations on this but the record won't show.... anybody have an idea what I'm doing wrong?

=====================

getAuth();

function getAuth() {
    var user = new GlideRecord('sys_user');
    user.get(gs.getUserID());
    If(user.u_authorised == 'true'); {
        return true;
    }
}

=====================

1: Record producer shows for all users on the portal when the 'Available for' list isn't populated. 

2: When I add the user_criteria of 'Any User' to the 'Available for' option of the record producer it shows fine, so visibility is fine until I add this new custom user_criteria option instead of the 'Any User' criteria. 

3: I tried adding an else option to return false immediately after the 'return true' but I get an unexpected token error when adding that in. 

Many thanks in advance for any input!

 

1 ACCEPTED SOLUTION

hey @GabeCardiff i think there is a small type over there

getAuth();

function getAuth() {
    var user = new GlideRecord('sys_user');
    user.get(gs.getUserID());
    if(user.u_authorised == 'true' || user.u_authorised == true ) {
       answer= true;
    }
else
{
 answer=false;
}
}

try this 

View solution in original post

5 REPLIES 5

Mohith Devatte
Tera Sage
Tera Sage

hello @GabeCardiff ,try this below script

getAuth();

function getAuth() {
    var user = new GlideRecord('sys_user');
    user.get(gs.getUserID());
    If(user.u_authorised == 'true' ||user.u_authorised == true ) {
       answer= true;
    }
else
{
 answer=false;
}
}

Hope this helps 

please mark my answer correct if this helps you

Thanks for the input Mohith, 

I seem to be getting an unexpected token error... I've tried altering some elements of the script to see if that shifts it, but it's still throwing up that error:

find_real_file.png

hey @GabeCardiff i think there is a small type over there

getAuth();

function getAuth() {
    var user = new GlideRecord('sys_user');
    user.get(gs.getUserID());
    if(user.u_authorised == 'true' || user.u_authorised == true ) {
       answer= true;
    }
else
{
 answer=false;
}
}

try this 

Hey @Mohith Devatte , you are a gentleman and a scholar good sir! Thanks very much for your assistance on that, it's sincerely appreciated 🙂