How to hide widget based on user role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 04:43 PM
So I have searched the community near and far and have not been able to find a solution.
I have cloned the ICON Link widget and need to now set the visibility of this based on the logged in user having a specific role.
If they have the role show the widget, if they don't have the role don't show the widget.
It seems simple enough, but I am new to ng-if angular and the data. options.schema stuff
I really could use some help with some sample code on how to achieve this.
Thank you very much
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 04:57 PM
What I have tried is to create option
always_show (boolean)
Server Script:
(function(){
var gr = $sp.getInstanceRecord();
data.href = $sp.getMenuHREF(gr);
data.target = options.target || "";
var lUser = gs.getUserID();
var gRole = new GlideRecord('sys_user_has_role');
gRole.addQuery('role', 'sp_password_services');
gRole.addQuery('user', 'lUser');
gRole.query();
if(gRole.next()){
options.always_show = true;
}
})();
Added to the top <div in html the following:
<div ng-if="{{::options.always_show == 'true'}}">
It's not working 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 10:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 03:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 04:14 PM
Jaspal,
I created a new widget from the copy icon link widget, and set the role on this new widget.
It seems to have worked.
I think the problem is that I had multiple instances of the copy of icon link widget on the page and it was not working.
At least I am assuming thats what it was.
I am going to test this theory by trying to add a role again to the copy icon link widget, I have 2 instances of this on the portal.
If it does not hide it based on role then I will venture to guess that is the case.
Will let you know what I find out.
Thank you for your reply
Tricia