The CreatorCon Call for Content is officially open! Get started here.

How to set a default value for a Select Box

Colleen1
Tera Contributor

We would like to set a default value for a Select Box on a form based upon a selection of another Select Box.  In our scenario, the user would pick "Tax Changes & Commodity Code" from this select box.

find_real_file.png

We would want the following select box, below, to populate "Tax" as the default value in this Select Box (aka put it at the top).  So basically, the dropdown, where the down arrow is, would be populated with "Tax" but the user still could pick from any of the other options.  We would do the same if someone picked "Add/Activate/Deactivate Accounts or BU" in the list above, it would default to "Accounting", and so on.  We cannot figure our with either g_form.setValue or g_form.addOptions or something else how to make this happen.

find_real_file.png

Any assistance would be greatly appreciated.

Thank you,

Colleen 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Colleen,

You'll need to create an onChange Catalog Client Script when the first variable changes.  Your script will start out something like this.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   if(newValue == 'Tax Changes...'){//replace with the Value of your choice
     g_form.setValue('variable_name', 'Tax');//replace with your variable name and the choice Value	
   }
}

Once you have it working for the first example, copy the three lines of the if block and modify for every newValue choice.  Be sure to use the exact choice values and not the labels.

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Hi Colleen,

You'll need to create an onChange Catalog Client Script when the first variable changes.  Your script will start out something like this.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   if(newValue == 'Tax Changes...'){//replace with the Value of your choice
     g_form.setValue('variable_name', 'Tax');//replace with your variable name and the choice Value	
   }
}

Once you have it working for the first example, copy the three lines of the if block and modify for every newValue choice.  Be sure to use the exact choice values and not the labels.

Thank you Brad!!!  We spent about a couple hours yesterday going back and forth to get this to work.  And it worked!!! Thank you!!

You are welcome!

Trying this code for my State and Status of Request fields. It's not working. Also note that this is not a Catalog Client Script.  It's just a Client Script on the form in the UI Platform.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var state = g_form.getValue('state');
var status = g_form.getValue('u_status_of_request');

if (newValue=='3'){
g_form.setValue('status','closed');