Can I restrict selection of an option on a select box variable to certain role?

Hola Ola
Giga Guru

Hello all, 

I am looking for a way, if there's any, to have the options in a select box be selectable by role. 

 

As shown in he attachment, I would like for only users with certain role OR group membership to ONLY be able to select (or see) the Purchase option. 

 

HolaOla_0-1721047880492.png

Any help or suggestion would be appreciated.

 

Thanks

 

1 ACCEPTED SOLUTION

Hey, 

it should be like this

function onLoad() {
  if (!g_user.hasRole('rtls_purchase_view')) {
        g_form.removeOption('type_of_purchase_replacement',"Purchase");
    }
}

, also remove <>, those are just to show where you have to place the fields

 

-Anurag

View solution in original post

7 REPLIES 7

Anurag Tripathi
Mega Patron

Hi,

What you can do is, Check if the user has the role, if not then remove Purchase form the dropdown. 

Something like

    if (!g_user.hasRole('<ROLE NAME>')) {
        g_form.removeOption('<FIELD NAME>',"<CHOICE VALUE>");
    }

 

-Anurag

Thanks Anurag,

Please pardon my obvious lack of understanding, I did this and here's what I got.

 

HolaOla_0-1721049143763.png

 

Hi @Hola Ola 

You don't need to remove  function

function onLoad() {
   //Type appropriate comment here, and begin script below
  }
because of missing onload function you are getting the error.

Hi @Hola Ola,

 

You need to wrap the if statement within an onLoad function as follows:

 

 

function onLoad() {
    if (!g_user.hasRoleExactly('the_role_name_required')) {
        g_form.removeOption('the_field_name', 'the_value_name_to_remove');
    }
}

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie