- 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 01:17 AM
Paste your HTML code here, there will be a change in HTML code as well.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 01:20 AM
As I understand I need to just need to add one line in HTML. For example, if it returns True, then in top of my html I can write condition on very first div ng-if= SE user = true then show widget, am I correct?
<div class="panel panel-{{options.color}} b" ng-if="::(SE == true)">
<div class="iconlink" ng-class="{'high-contrast': accessibilityModeEnabled}">
<!--// Top Icon -->
<a ng-if="::(options.link_template == 'Top Icon' || !options.link_template)" ng-href="{{::data.href}}" class="top_icon {{::options.class_name}}" target="{{::data.target}}">
<div class="m-b fa fa-{{::options.glyph}} fa-4x {{::options.class_name}} text-{{::options.color}}"></div>
<h2>{{::options.title}}</h2>
<span class="text-muted">{{::options.short_description}}</span>
</a>
<!--// Circle Icon -->
<a ng-if="::(options.link_template == 'Circle Icon')" ng-href="{{::data.href}}" class="circle_icon {{::options.class_name}} text-{{::options.color}}" target="{{::data.target}}">
<span class="fa fa-stack fa-2x" aria-hidden="true">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-{{::options.glyph}} fa-stack-1x fa-inverse"></i>
</span>
<h2>{{::options.title}}</h2>
<span class="text-muted">{{::options.short_description}}</span>
</a>
<!--// Color Box -->
<a ng-if="::(options.link_template == 'Color Box')" ng-href="{{::data.href}}" class="color_box {{::options.class_name}} icon-link-background-{{::options.color}} text-white" target="{{::data.target}}">
<div class="fa fa-{{::options.glyph}} fa-3x {{::options.class_name}}"></div>
<h2>{{::options.title}}</h2>
<span>{{::options.short_description}}</span>
</a>
</div>
</div>
</div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 01:44 AM
try below:
(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")
{
data.region=true;
}
else {
data.region=false;
}
}
})();
HTML:
<div ng-if = "data.region">
<div class="panel panel-{{options.color}} b" ng-if="::(SE == true)">
<div class="iconlink" ng-class="{'high-contrast': accessibilityModeEnabled}">
<!--// Top Icon -->
<a ng-if="::(options.link_template == 'Top Icon' || !options.link_template)" ng-href="{{::data.href}}" class="top_icon {{::options.class_name}}" target="{{::data.target}}">
<div class="m-b fa fa-{{::options.glyph}} fa-4x {{::options.class_name}} text-{{::options.color}}"></div>
<h2>{{::options.title}}</h2>
<span class="text-muted">{{::options.short_description}}</span>
</a>
<!--// Circle Icon -->
<a ng-if="::(options.link_template == 'Circle Icon')" ng-href="{{::data.href}}" class="circle_icon {{::options.class_name}} text-{{::options.color}}" target="{{::data.target}}">
<span class="fa fa-stack fa-2x" aria-hidden="true">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-{{::options.glyph}} fa-stack-1x fa-inverse"></i>
</span>
<h2>{{::options.title}}</h2>
<span class="text-muted">{{::options.short_description}}</span>
</a>
<!--// Color Box -->
<a ng-if="::(options.link_template == 'Color Box')" ng-href="{{::data.href}}" class="color_box {{::options.class_name}} icon-link-background-{{::options.color}} text-white" target="{{::data.target}}">
<div class="fa fa-{{::options.glyph}} fa-3x {{::options.class_name}}"></div>
<h2>{{::options.title}}</h2>
<span>{{::options.short_description}}</span>
</a>
</div>
</div>
</div>
</div>
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 02:14 AM
hmm, when tested it does not show at all, tried impersonate other user which has location SE but widget not showing.
Not sure what else could be wrong. Any other ideas?