Client script to update the choices selected on a form

MyR
Tera Contributor

We have a list field on a form where users can select multiple options (for this discussion Airplane, Bicycle, Car and Not Applicable).

1. User selects Bicycle and Car.

2. User changes their mind and selects "Not Applicable". The previous two selections should be removed.

 

3. User selects Car again. Now the "Not Applicable" selection should be removed and replaced by the latest choice.

 

I did not find a way to do this using UI Policies and hence am trying Client Scripts. However, I am unable to figure out which event to use to get the previous value. The onchange event has the old value as of form load. But I need to get the previous changes that are not yet saved when the user stays on the page and performs the steps above sequentially. 

 

 

 

1 ACCEPTED SOLUTION

Vishal Jaswal
Giga Sage

Hi @MyR  You can create a UI policy (screenshot below) with Condition as "Field" Contains Not Applicable and Script > Execute if true

 

function onCondition() {
g_form.setValue('u_transport_medium', 'Not Applicable');
}

 

vishal_jaswal_2-1740679651568.png

 



vishal_jaswal_0-1740679481768.png



vishal_jaswal_1-1740679502044.png

 


Hope that helps!

View solution in original post

4 REPLIES 4

jgoldstein
Tera Contributor

you could use a UI Policy or client script for this:

g_form.clearValue('not applicable');

will clear out the check box value and just set it so that it runs when either of the two check boxes for "car" or "bicycle" have been marked. Then do the same for the "not applicable" field:

g_form.clearValue('car');

g_form.clearValue('bike');

Vishal Jaswal
Giga Sage

Hi @MyR  You can create a UI policy (screenshot below) with Condition as "Field" Contains Not Applicable and Script > Execute if true

 

function onCondition() {
g_form.setValue('u_transport_medium', 'Not Applicable');
}

 

vishal_jaswal_2-1740679651568.png

 



vishal_jaswal_0-1740679481768.png



vishal_jaswal_1-1740679502044.png

 


Hope that helps!

Thank you for the detailed screenshots. It was helpful and I am able to accomplish steps 1 and 2 using this approach with UI policies instead of using client scripts. I am not yet able to fully solve for step 3 easily, but as a workaround, I will force the user to remove "Not Applicable" before adding one of the other options.

Thank you.

Hello @MyR 

Step#3 or 3rd screenshot is from the Script tab of UI Policy.

Please mark the answer helpful if it resolved your issue.


Hope that helps!