GlideRecord/Script in User Criteria

patricklatella
Mega Sage

Hi friends,

I'm building a User Criteria and need to have the script check the value of field on the logged in user's record in sys_user.

Trying a couple ways to do this and not finding the correct script.   Anyone see why this isn't working?   the top part that is querying to get the gr.u_region is working fine.   It's the getDomain part that does not seem to be working.   The field on the sys_user table I'm looking to see if it "== 'CTS'" is [u_ad_domain].

Thanks!

answer();

function answer(){

var loc = gs.getUser().getRecord().getValue('location');

var gr = new GlideRecord('cmn_location');

gr.get(loc);

     

var getDomain = new GlideRecord('sys_user');

getDomain.addQuery('sys_id',gs.getUserID());

getDomain.query();

if(gr.u_region == 'EMEA' && getDomain.u_ad_domain == 'CTS'){

return true;

}

}

1 ACCEPTED SOLUTION

Actually this is perfect



answer();



function answer(){


var getDomain = new GlideRecord('sys_user');


getDomain.addQuery('sys_id',gs.getUserID());


getDomain.query();



if (getDomain.next())


{


if(getDomain.location.u_region == 'EMEA' && getDomain.u_ad_domain == 'CTS'){


        return true;


}


}


}



Thanks,
Sanjiv



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

11 REPLIES 11

Actually this is perfect



answer();



function answer(){


var getDomain = new GlideRecord('sys_user');


getDomain.addQuery('sys_id',gs.getUserID());


getDomain.query();



if (getDomain.next())


{


if(getDomain.location.u_region == 'EMEA' && getDomain.u_ad_domain == 'CTS'){


        return true;


}


}


}



Thanks,
Sanjiv



Please mark this response as correct or helpful if it assisted you with your question.

we need highlighted line as well.



var getDomain = new GlideRecord('sys_user');


getDomain.addQuery('sys_id',gs.getUserID());


getDomain.query();


if(getDomain.next()){


}


Ok based on my understanding of the requirement below script should work.



answer = checkUser();


//gs.print(checkUser());



function checkUser() {


var return_flag = false;


var grUser = new GlideRecord('sys_user');


grUser.addQuery('sys_id', gs.getUserID());


grUser.query();


if(grUser.next()) {


if (grUser.location.u_region == 'EMEA' && grUser.u_ad_domain == 'CTS') {


//if (grUser.location.name == '100 South Charles Street, Baltimore,MD') {


return_flag = true;


}


}


return return_flag;


}


patricklatella
Mega Sage

hey everyone, thanks so much for the input!   At first I tried each of these scripts and none worked...but I'm wondering if there's a funny issue related to our recent upgrade in DEV to Jakarta.   To create my User Criteria record I did an "Insert & Stay" from an existing record, as opposed to creating "New".   Then tried the above scripts above with no luck.



When I went ahead and just created a User Criteria just from "New", both Anil's and Sanjiv's scripts work.



Not sure if that's expected behavior, but good to know moving forward.



thanks guys!