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.

Service Catalog visability based on users "title"

EcFuhrmann
Tera Contributor

I am looking for assitance with away to create a user critiera profile based on the title of a users profile. I need to only allow users with "HR" in their title under their users profile to see a form in the service catalog. Is there away to use a script to get this to work? 

1 ACCEPTED SOLUTION

@EcFuhrmann The script which I have provided validates if the title contains "HR" (indexOf) and only those users will be able to access it. 

 

Below is another e.g, 

 

   if (title.indexOf('vp') > -1 || title.indexOf('director') > -1 || title.indexOf('manager') > -1) {
        return true;
    }
    return false;
}

 

 

Note: Converted the title to lowercase and have used in above "If" condition. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

View solution in original post

5 REPLIES 5

Sujatha V M
Kilo Patron
Kilo Patron

@EcFuhrmann You can create a "User Criteria" as below in advanced section add the script to identify the title and add it to the catalog item "Available For" related list. 

 

checkCondition();

function checkCondition() {

    var rec = new GlideRecord('sys_user');
    rec.addQuery('sys_id', user_id);
    rec.query();
    if (rec.next()) {
        var title = rec.getValue('title');
        if (title == 'HR Executive' || title.indexOf('HR') > -1) {
            return true;
        }
    }
    return false;

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Astik Thombare
Tera Sage
Tera Sage

Hi  @EcFuhrmann ,,

 

Please check below thread -

 

https://www.servicenow.com/community/developer-forum/how-to-create-user-criteria-based-on-title/m-p/...

 

             If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

 

Astik

EcFuhrmann
Tera Contributor

What do I do when the titles are not all the same and I want to use have it look if the title contains "HR"? These scripts are pointed to one title only. 

@EcFuhrmann The script which I have provided validates if the title contains "HR" (indexOf) and only those users will be able to access it. 

 

Below is another e.g, 

 

   if (title.indexOf('vp') > -1 || title.indexOf('director') > -1 || title.indexOf('manager') > -1) {
        return true;
    }
    return false;
}

 

 

Note: Converted the title to lowercase and have used in above "If" condition. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.