- 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 01:19 AM
Hi,
Can you try this script and see if it works?
var locationId = gs.getUser().getRecord().getValue('location');
var usrLocation = new GlideRecord('cmn_location');
usrLocation.addQuery('sys_id', locationId);
usrLocation.query();
gs.log("Row count=" + usrLocation.getRowCount());
if (usrLocation.next()){
var userRegion = usrLocation.getValue('u_gyregion_code');
gs.log("userRegion=" + userRegion);
if(userRegion == "NA") {
answer = true;
}else {
answer = false;
}
}
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 01:36 AM
We have a widget announcement which we want to hide for the NA Region users. So , in the widget we added this user criteria under the cannot view. This widget should be hidden but it but it still showing on the portal..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 01:26 AM
change the first line.
it should be
gs.getUser().getLocation()
var locationId = gs.getUser().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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 01:35 AM
Yes Harsh, i already changed the first line of the code and run the code in the background script and it showing the output as expected. We have a widget announcement which we want to hide for the NA Region users. So , in the widget we added this user criteria under the cannot view. This widget should be hidden but it still showing on the portal.