Hide a component on workspace based on role

Tapish Sharma1
Kilo Sage

Hi Folks, 

I have added a data visualization single score component on landing page of a workspace. I want to make it visible to only certain roles .... How can I configure it ? 

1 ACCEPTED SOLUTION

kamlesh kjmar
Mega Sage
Mega Sage

Hello Tapish,

You can use componen visibilty for this. Follow the below steps to acheive it :

 

1. To do this click on the component that you need to hide and go to the configuration panel and click on 'Edit component visibility' button indicated by 'eye' symbol, shown below

kamlesh8_0-1666190679267.png

 

2. Hover over the Hide component, it will show you some buttons. Click on the code button indicated by '</>' sysmbol. This will open a popup page where you can script

kamlesh8_1-1666191032818.png

 

3. Use the below script and modify role as per your requirement:

 

/**
 * @Param {params} params
 * @Param {api} params.api
 * @Param {TransformApiHelpers} params.helpers
 */
function evaluateProperty({
    api,
    helpers
}) {
    var roles = api.context.session.user.roles;
    if (roles.indexOf('admin') > -1 || roles.indexOf('cmdb_manager') > -1)
        return false;
    else
        return true;

}
 
kamlesh8_2-1666191329209.png

 

 
Above script says show the report only to people having admin role or cmdb_manager role. For every one else it will be hidden.
 
Please let me know if this works/don't works for you.
 

I Hope this helps.

 

Please mark this helpful if this helps and mark as correct if this solves your issue.

 

Regards,

Kamlesh

 

 

 

 

View solution in original post

10 REPLIES 10

Can we add condition based on user group?

Hello, I have the same requirement. Were you able to add?

Hello kamlesh,

My requirement is, If there is no data on the visualization component i need to hide the component. Kindly help me in scripting.

 

Kindly check the component on below screenshot:

 

gowthamaa_mohan_0-1711092889584.png

 

Hi Kamlesh,

 

Thank you for this.. Its not letting other users than admin role to edit. But I also wants to add condition that only the quick links which are marked global as true(field on quick links table)to be restricted for non admin users so how can I write this in the same code? Can you please provide me .

 

 

Firas Kh
Tera Expert

Hello, if i need this condition to check the role of the current viwer of the hr profile (user presence) what i need to change in the "api.context.session.user.roles;" in order to get the current viewer of that page and to get his roles.

thanks!