Restricting visibility of UI Macro based on roles

Brian Broadhurs
Tera Contributor

Hi, does anyone know how to restrict the visibility of a UI Macro - for example the user_show_incidents that comes out of the box? I want to make this available only to users with itil role so it is not visible to self-service users.

There is something in the domain_select UI macro that looks like it might do the trick - a function called WelcomeWidgetSelectControl - but I don't know how to use this.

Brian Broadhurst

2 REPLIES 2

Mark Stanger
Giga Sage

It's probably easiest to just restrict Write permissions on the 'Caller' field on the incident form (or whatever field you're using the macro on). You can test on the /demo instance. It restricts write permissions on the 'incident.caller_id' object to the 'itil' role using system security. The icon doesn't show up if the user doesn't have write permissions.

If that doesn't work for you for whatever reason, then you'll have to modify the UI macro itself. That means that you won't get upgrades to that UI macro record in the future. If you choose to go that route then this UI macro script should do what you want.



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:if test="${gs.hasRole('itil')}">
<g:evaluate var="jvar_guid" expression="Packages.com.glide.util.Guid.generate(this);" />
<j:set var="jvar_n" value="show_incidents_${jvar_guid}:${ref}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}"
onclick="showRelatedList('${ref}'); "
title="${gs.getMessage('Show related incidents')}" image="images/icons/tasks.gifx"/>

<script>
// show related list
// todo: should be part of the PopupWindow class
// todo: needs new stack name
function showRelatedList(reference) {
var s = reference.split('.');
var tableName = s[0];
var referenceField = s[1];
var url = tableName + '_list.do?';
url += '&amp;';
var v = g_form.getValue(referenceField);
url += 'sysparm_query=' + referenceField + '=' + v;

var w = getTopWindow();
w.popupOpenFocus(url, 'related_list', 950, 700, '', false, false);
}

</script>
</j:if>
</j:jelly>


Hi Mark Stanger,

I have the same case, users who don't have write permission for the "Short description" field in closed incidents can't see the "Search Knowledge" button. I'm researching the relationship between write permission and UI macro but haven't found any documentation about it. Could you please give me some references or documents regarding this?

 

Thank you in advance,