- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 01:07 AM
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!!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:01 AM
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;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:20 AM
i just tried that way nothing any logic behind that.
i think admin can see this. it's normal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:22 AM
Thanks Harsh but Why it is not run without adding function?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:26 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:28 AM
This one also working fine!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:33 AM
Glad it worked.
Kindly mark my reply as correct and close this thread.