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

Brian Lancaster
Tera Sage

Before var userRole add g_form.removeOption(variable name, choice value). You have to hide otherwise it will always be there even if you have script to add it. In the future when you want to provide script please do not include screenshot but use the code sample in the HTML community editor.

BrianLancaster_0-1727186611924.png

 

 

function onLoad() {
       g_form.removeOption('what_type_of_catalog_request','deploy_catalog_builder_item');
       var userRole = g_user.hasRoleExactly('catalog_builder_editor');

       if (userRole == true) {
           g_form.addOption('what_type_of_catalog_request','deploy_catalog_builder_item');
       }
       }

 

 
   Unfortunately, that did not work. Is this because we are accessing this form through an Order Guide? 
 

Does it work if you access the item itself? Are they using the Service Portal in order to view the order guide?

It is not working on the catalog item itself. Yes, we are using Service Portal to access the Order Guide.