Remove variable option based on user roles

melsarrazin
Tera Contributor

I am trying to remove the 'Deploy Catalog Builder Item' option from the choices if the logged in user does not have the catalog_builder_editor role. 

 

Currently this catalog item is nested in an Order Guide. I have tried added Client Scripts to the Catalog Item and the Order Guide with no success. 

 

Below is the script I have put together from looking at other similar postings. Is there something obvious I am doing wrong? Thanks in advanced!

 

melsarrazin_1-1727185270031.png

 

 

melsarrazin_0-1727185024617.png

melsarrazin_2-1727185382807.png

 

 

1 ACCEPTED SOLUTION

Change the UI Type on the client script to all. You have it set to desktop which mean it will only work in the standard UI.

View solution in original post

8 REPLIES 8

Change the UI Type on the client script to all. You have it set to desktop which mean it will only work in the standard UI.

That worked! thank you

hi @melsarrazin 

try bellow updated script once:

function onLoad() {
    // Check if the user has the 'catalog_builder_editor' role
    var userRole = g_user.hasRoleExactly('catalog_builder_editor');
    
    if (!userRole) {
        // If the user does not have the role, remove the option
        g_form.removeOption('what_type_of_catalog_request', 'deploy_catalog_builder_item');
    } else {
        // If the user has the role, add the option back
        g_form.addOption('what_type_of_catalog_request', 'deploy_catalog_builder_item', 'Deploy Catalog Builder Item');
    }
}

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

 

Thank you for the response. This script was unsuccessful in hiding that option.