The CreatorCon Call for Content is officially open! Get started here.

Show icon link widget based on user location

Julius28
Tera Expert

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; 

}

}

})();

 

 

1 ACCEPTED SOLUTION

(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!

View solution in original post

11 REPLIES 11

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.


Raghav
MVP 2023
LinkedIn

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;

}

}

 

 

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;

}

}

 


Raghav
MVP 2023
LinkedIn

SE is value from Configure dictionary. Tried but still does not work.

which field on user table or location table does store "SE" value? if it is from configure dictionary, which field's configure dictionary?


Raghav
MVP 2023
LinkedIn