Can you switch Service Portal container links depending on user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:46 PM
The ask is that the most used Catalog Items be linked on the Service Portal under the "Examples" so we have quick shortcuts to them.
The issue is that not all Catalog Items are accessible to everyone, some are limited per User Criteria.
Is there a way to dynamically decide which HTML links display to a user, so that what they see is always applicable?
See screenshot below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 12:57 AM
Hello @MBarrott
Let's take a simple example: if you want to show certain links only to users from a specific group or company, and hide them from others, you can control this using a flag variable. Based on this flag, you can decide whether to display the actual content or show something else.
You can first check whether the user belongs to a specific group or company.
Based on that condition, set a flag variable (e.g., isAllowedUser = true or false).
// Server Script
(function() {
var userGR = gs.getUserID();
//var userID = userGR.getID();var targetGroup = 'YOUR_GROUP_SYS_ID'; // Replace with actual group sys_id
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userGR );
gr.addQuery('group', targetGroup);
gr.query();data.showLink = gr.hasNext(); // true if user is in the group
})();
Now, in your HTML template (Widget Template), use ng-if or a similar directive to conditionally show/hide elements.
<!-- Widget Template -->
<div>
<a ng-if="data.showLink" href="/some-page">Go to Special Page</a>
<p ng-if="!data.showLink">You do not have access to this content.</p>
</div>
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You