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

Michael Fry1
Kilo Patron

You should create a second variant on that page. Then apply an audience based on roles that should see the variants. For example, you have 2 variants, one with the data viz, one without. The audience would route a person with x role to the variant with the data viz. The person without x role is routed to the variant without the data viz.

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

 

 

 

 

Hi @Tapish Sharma1 ,

 

Could you please let us know if your problem got solved ? If not, please let us know issue you are facing, so that we can help further.

 

If your issue is resolved please help us close this thread by accepting right solution, so that it could help others.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

Hi @Tapish Sharma1 ,

 

This is a follow up. This thread is still not closed. If your issue is resolved, could you please help us close this thread by accepting appropriate Answer as solution.

 

Thanks,

Kamlesh