Remove Select Box Option if user does NOT have role

smfoister
Giga Expert

Hello,

I have a catalog item that has a Select Box variable. One of the options needs to be unavailable if the user does NOT have a specific role. 

For people that DO have the role the form seems to be working normally with all options available, however when testing with a user account that does NOT have the role the entire bottom half of the form is missing, so obviously there's some javascript bug.

Here is the code I'm using, can you tell me what I'm missing here? Still a novice at scripting.

function onLoad() {
   //Remove IIO Budget option if user does NOT have iio_budget_user role
  
if (g_user.hasRole('iio_budget_user')){
	return;
}
else g_form.removeOption('select_funding_source', 'IIO Funded');
}	
1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, perhaps the return; is stopping the form from loading.

How about trying a simplified version?

if (!g_user.hasRole('iio_budget_user')) {

 g_form.removeOption('select_funding_source', 'IIO Funded');

}

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, perhaps the return; is stopping the form from loading.

How about trying a simplified version?

if (!g_user.hasRole('iio_budget_user')) {

 g_form.removeOption('select_funding_source', 'IIO Funded');

}

Seems like this would work, but for some reason it's doing the same thing, it's not showing the bottom of the form where this variable exists. 

 

The variable is inside of a variable set, here's the code just in case I've done something stupid:

 

function onLoad() {
   //Remove IIO Budget option if user does NOT have iio_budget_user role
  
if (!g_user.hasRole('iio_budget_user')) {

 g_form.removeOption('select_funding_source', 'IIO Funded');

}
}

Sorry I found another issue that was causing the form to not load properly, your solution above works perfectly. Thank you!