User criteria script

LucasEduarF
Tera Contributor

Hi, I am trying to create a user criteria to check the user's state using a script. I noticed that in sys_user there is a reference field called location.parent pointing to the cmn_location table. I don’t know how to do this dot walk. I also noticed that when opening the record in the cmn_location table, the field that contains the value I want is name.

 

this is the script i build: 

function checkCondition(){
    var user =  new GlideRecord('sys_user');
    user.get(gs.getUserID());
    if (user.location == 'PE') {
        return true;
    }
    return false;
}
6 REPLIES 6

@LucasEduarF 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Yes, i did help me, but i had to make a small change, this was the script i used in the end: 

var user_id = gs.getUserID();
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', user_id);
user.addQuery('location.parent.name', 'PE');
user.query();
answer = user.hasNext();