- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 12:57 AM - edited 12-15-2022 01:06 AM
Hi!
I'm stuck on one task, where I need to create custom icon link widget which can be seen only by users who are from specific country.
I cloned Icon link widget , did visual changes to it(icon, location in portal, links etc now I'm working on server side script and HTML part.
My goal is to custom server side script so widget shows only for people which are from location "SE".
I have checked community and some other forums but cannot make it work.
Can you please comment what I need to correct so the widget is only visible for logged on user from country "SE"?
Thank you in advance
(function(){
var gr = $sp.getInstanceRecord();
data.href = $sp.getMenuHREF(gr);
data.target = options.target || "";
checkCondition();
function checkCondition(){
var locationId = gs.getUser().getLocation();
var usrLocation = new GlideRecord('cmn_location');
usrLocation.addQuery('sys_id', locationId);
usrLocation.query();
if(usrLocation.next())
{
if(userRegion == "SE")
{
return true;
}
else {
return false;
}
}
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 10:24 PM - edited 12-16-2022 06:55 AM
(function(){
var gr = $sp.getInstanceRecord();
data.href = $sp.getMenuHREF(gr);
data.target = options.target || "";
data.region = false;
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", gs.getUserID());
user.setLimit(1)
user.query();
if (user.next()) {
if(user.country == 'SE'){
data.region=true;
}
}
})();
Hi! I figured it out myself, using different scripting approach. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 02:25 AM - edited 12-15-2022 02:27 AM
Your serve code doesnt seems to be correct. What is
userRegion
Where is this coming from? If this is a field on location table it should be a dotwalk with usrLocation.
Correct your server script, the it will work fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 03:25 AM
What do you mean with correcting server side script? Where there is error?
And what do you think of this approach? However, it also does not work.
(function(){
var gr = $sp.getInstanceRecord();
data.href = $sp.getMenuHREF(gr);
data.target = options.target || "";
checkCondition();
function checkCondition(){
var locationId = gs.getUser().getLocation();
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", gs.getUserID());
user.setLimit(1)
user.query();
if (user.next()) {
var userCountry = user.location.country;
}
if(userRegion == "SE")
{
data.region=true;
}
else {
data.region=false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 03:32 AM
Try below code and check my comments:
function(){
var gr = $sp.getInstanceRecord(); // is this required? if not remove it?
data.href = $sp.getMenuHREF(gr); // is this required? if not remove it?
data.target = options.target || ""; // is this required? if not remove it?
checkCondition();
function checkCondition(){
var locationId = gs.getUser().getLocation(); // is this required? if not remove it?
var userCountry ='';
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", gs.getUserID());
user.setLimit(1)
user.query();
if (user.next()) {
userCountry = user.location.country; // is "SE " country?
}
if(userCountry == "SE")
{
data.region=true;
}
else {
data.region=false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 04:26 AM
SE is value from Configure dictionary. Tried but still does not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 04:30 AM
which field on user table or location table does store "SE" value? if it is from configure dictionary, which field's configure dictionary?