- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 09:47 AM
Hello!
I have a variable set that I'd like to make visible to only those with the a specific role assigned. I've tried various combinations of UI Catalog Policy and Catalog Client Scripts looking at the variable set (preferred setup if possible for ease of re-use) and a Catalog Item, but the best I've been able to accomplish is making the question itself mandatory/non-mandatory. I'm using versions of (onCondition also having been changed to onLoad and the variable_set also swapped out to the specific variable_name):
function onCondition() {
if (g_user.hasRole('role')) {
g_form.setDisplay('variable_set', true);
g_form.setMandatory('variable_name', true);
}
}
The variable name is Mandatory if the variable set is visible and has two items assigned to it that are visible based on out-of-the-box Catalog UI Policy setup. The variable_name itself is set up as non-mandatory since that will override the scripting to make it appear regardless.
Any help is greatly appreciated.
Thank you,
Erik Nelson
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 10:11 AM
Hi Erik,
For your requirement please use the below onLoad Catalog Client Script on the particular Item. It's working in my instance successfully. Also please make sure that no other Catalog Client Script or UI Policy should override this one.
function onLoad() {
if (!g_user.hasRole('admin')){
g_form.setDisplay('common_comments', false);
g_form.setMandatory('input', false);
}
else{
g_form.setDisplay('common_comments', true);
g_form.setMandatory('input', true);
}
}
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 12:32 PM
Thank you Amlan!! This is exactly what I needed. Also on a side note, it works perfectly assigning it to the Variable Set instead of directly to the Catalog Item.
Erik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2020 12:00 PM
Here is what I did:
1. Create a CheckBox variable.
2. Set its default value to javascript:gs.getUser().hasRole('role')
3. Hide this CheckBox variable through UI Policy.
4. Create a UI Policy to show the variable that you want to display if the user has the required role. Use the value of the CheckBox variable in When to apply condition.