I need to create a user criteria with specific departments

Sri56
Tera Contributor

Hi Team,

I need to create a catalog user criteria with specific department name starts with 'GS'

I need to advanced option.

Please help!

 

Thanks in advance,

Sri

5 REPLIES 5

shloke04
Kilo Patron

Hi,

You can write the User criteria Script as below:

answer = checkCondition();

function checkCondition() {

var user = new GlideRecord('sys_user');
user.get(gs.getUserID());

var dept = user.dept.name;

if(dept == 'Value' || dept == 'Value')
return true;
else
return false;

}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

shloke04
Kilo Patron

In the script above just give the Department value which you want to evaluate and you should be good with your requirement.

Say if there are multiple Department for which you want to check then you can update the script as below:

answer = checkCondition();

function checkCondition() {

    var user = new GlideRecord('sys_user');
    user.addQuery('sys_id', gs.getUserID());
    user.addEncodedQuery('department.nameSTARTSWITHGS'); // Check for Department start with GS 
    user.query();
    if (user.next()) {
        return true;
    } else {
        return false;
    }


}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Sanjay Bagri1
Tera Guru

Hi Sri,

Please could you go through below links:

Apply user criteria to items and categories

 http://www.servicenowguru.com/scripting/user-object-cheat-sheet/

 

Set the condition as per your requirment: 

gs.getUser().getRecord().getValue('active') == true

for more info go to advance script options

 *** Help with User Criteria Advanced Script

If my answer helps you then please mark my answer is correct and helpful.

Thanks

Sanjay Bagri

QBrainX Pvt. Ltd.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sri,

As per best practice you can use user_id to get logged in user sysId and don't use gs.getUserID()

Use this script

var rec = new GlideRecord('sys_user');
rec.addQuery('sys_id', user_id);
rec.addEncodedQuery('department.nameSTARTSWITHGS');
rec.query();
answer = rec.hasNext();

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader