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

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

@Julius28 Great that worked!!!


Raghav
MVP 2023
LinkedIn