Hide widget based on Region of logged in user

kun1
Tera Expert

Hi Team, 

We have to hide the widget or page based on the region code of logged in user. To achieve this, i have created a User criteria and write a script in it but its not working.

var locationId = gs.getUserID().getLocation();
var usrLocation = new GlideRecord('cmn_location');
usrLocation.addQuery('sys_id', locationId);
usrLocation.query();
gs.log("Row count=" + usrLocation.getRowCount());
while (usrLocation.next())
{
var userRegion = usrLocation.getValue('u_gyregion_code');
gs.log("userRegion=" + userRegion);
if(userRegion == "NA")
{
answer = true;
}
else {
answer = false;
}
}

Please take a look and help me to correct this.

Thanks!!

1 ACCEPTED SOLUTION

try now. 

 

checkCondition();

function checkCondition(){

var locationId = gs.getUser().getLocation();

var usrLocation = new GlideRecord('cmn_location');
usrLocation.addQuery('sys_id', locationId);
usrLocation.query();
if(usrLocation.next())
{
var userRegion = usrLocation.getValue('u_gyregion_code');

if(userRegion == "NA") 
{
return true;
}
return false; 

}

}

View solution in original post

14 REPLIES 14

i just tried that way nothing any logic behind that. 

i think admin can see this. it's normal. 

 

 

Thanks Harsh but Why it is not run without adding function?

try now. 

 

answer=false;

var locationId = gs.getUser().getLocation();

var usrLocation = new GlideRecord('cmn_location');
usrLocation.get(locationId);
var userRegion = usrLocation.getValue('u_gyregion_code');

if(userRegion == "NA") 
{
answer= true;
}


This one also working fine!!

Glad it worked. 

 

Kindly mark my reply as correct and close this thread.