Variable or Variable Set Visible by Role in Service Catalog

Erik Nelson
Kilo Sage

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

1 ACCEPTED SOLUTION

amlanpal
Kilo Sage

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


View solution in original post

6 REPLIES 6

BALAJI40
Mega Sage

You are saying that the variable name is not going to be mandatory, is it correct?


show the screen shot of your catalog item.


check is there any catalog client script or ui policies overriding also.


The variable set/variable name should only be visible and mandatory if the "role" requirement role is met.   I have managed to turn on/off the mandatory piece using a variant of the script above, but not the visibility.   Ideally, I'd like the policy to be part of the variable set so that I can create it once and re-use since this will be on multiple items.   Currently, the variable set and intial variable name are non-mandatory



Thank you


Madhu27
Tera Expert

Here you go



Re: Hide variable set based on role or groupe



PS: Please hit like/helpful, if it helps


amlanpal
Kilo Sage

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