On Change Client form Remove option not working Dynamically

Kristina2
Tera Contributor

Hi all, 

I have a simple requirement , but not working as expected . 

As per two fields , i have to remove a option 

Field 1 : IF u_os_install_required is NO 

Field 2 : OR  IF u_os_installation_team is "BELLMAWR" or "CUSTOMER" . 

 FIELD 3 : u_database_installation_team - REMOVE THE OPTION "PPS"

This is working as expected . 

 

BUT before submitting, if they change their mind and want to make changes . It is not making the changes . 

 

Also tried form getValue(), this method is not working too . 

find_real_file.png

find_real_file.png

12 REPLIES 12

Noah Drew
ServiceNow Employee
ServiceNow Employee

Hi Kristina!

This is the way Client Scripts work.

Once the value is removed from the form, it will stay like that unless the form is reloaded or added back.

You can use an add to your conditional and re-add the Option with g_form.addOption.

Hope that helps!

If it did, please mark as Helpful and consider setting this reply as the Correct Answer to the question, thanks!

Elijah Aromola
Mega Sage

You will have to add code that re-adds that option after you delete it. The user will see this value again if they refresh the page though. Normally when I do remove options with If statements, I add an "else" that re-adds the option to the form. Such as:

if(newValue != 'value') {
   g_form.removeOption('field', 'value';
} else {
   g_form.addOption('field', 'value')
}

Please mark this as correct/helpful if it answered your question!

Adrian Ubeda
Mega Sage
Mega Sage

Hi, 

 

I think you should control how the user returns to the 'zero' state in the form and the behaviour of the choice options, it should be something like this:

if(newValue === 'no') {
  g_form.removeOption('u_database_installation_team','PPS-TIE Infrastucture team');
}else{
  g_form.addOption('u_database_installation_team','PPS-TIE Infrastucture team');
}

 

If t was helpful, please give some positive feedback.
Thanks,

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Kristina2
Tera Contributor

Guys , 

 

I have already tried the If else part , it doesn't work . And it doesn't work without a reload