g_form.removeOption not working as expected on onLoad client script

Shamir Mawji
Kilo Expert

Hi, I am trying to hide 2 question choice options that are not required temporariliy.

I am trying to use the g_form.removeOption but I cannot get this to work. I am not sure if this is because of what I am doing... 

I am using the below... where u_access_type is the question field and loss and profit are the value of the option.

function onLoad() {
g_form.removeOption('u_access_type', 'loss');
g_form.removeOption('u_access_type', 'profit');
}

Any help appreciated!

8 REPLIES 8

Service_RNow
Mega Sage

Hi,

follow link: client-scripts-scripting/removing-disabling-choice-list-options

Please: Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact

Anurag Tripathi
Mega Patron
Mega Patron

What happens when you run the same via javascript executor??

-Anurag

Rahul Kumar17
Tera Guru

hi 

I m given one Example!

//Remove the 'Closed' state option if the user is not an admin and state is not 'Closed'


function onLoad() {
   var isAdmin = g_user.hasRole('admin');
   var state = g_form.getValue('state');
   if (!isAdmin && (state != 7)){
      //alert('Current user is not an admin');
      g_form.removeOption('state', '7');
   }
}

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

SaiRaviKiran Ak
Giga Guru

You should only remove the option if it is not the currently-selected option when the form loads.