How to make Yes/No field populate elsewhere?

Eli Hurst
Kilo Contributor

I have a Yes/No variable, and the entry needs to get populated in 2 Yes/No read-only boxes farther down the form. Is there a simple script to make this happen?

1 ACCEPTED SOLUTION

Good point! It's a Yes/No field so there's only 2 choices so that'll do.

Need to check "Reverse if false" in that case.

View solution in original post

12 REPLIES 12

Tony Chatfield1
Kilo Patron

Hi, if you are wanting to populate the values in the UI, IE when the field is changed update the form values
Then you would use an onChange() client script against the field that is changed, then set the target field values based on the newValue.
either

//Values will always match the source field
g_form.setValue('yourFieldName1', newValue);
g_form.setValue('yourFieldName2', newValue);

//Or set based on the newValue
if(newValue == 'true') {
        g_form.setValue('yourFieldName1', newValue);
        g_form.setValue('yourFieldName2', newValue);
    }

//Or set as required
if(newValue == 'true') {
        g_form.setValue('yourFieldName1', 'true');
        g_form.setValue('yourFieldName2', 'false');
    }

If you do not need to see the values in the form prior to saving, you could also use an onBefore() insert\updateBR and assign the values to the target fields based on the above scripts referencing the current object. IE

current.yourFieldName1 = current.yourReferenceField;
current.yourFieldName2 = true;

It's a Yes/No field type.

The first will work but the later would not because the code is comparing with "true" and "false" instead of "Yes" and "No".

Following is OK.

//Values will always match the source field
g_form.setValue('yourFieldName1', newValue);
g_form.setValue('yourFieldName2', newValue);

Other two should be as follows:

//Or set based on the newValue
    if (newValue == 'Yes')
        g_form.setValue('field3', newValue);
    else {
        g_form.setValue('field3', newValue);
    }

//Or set as required
if(newValue == 'Yes') {
        g_form.setValue('yourFieldName1', 'Yes');
        g_form.setValue('yourFieldName2', 'No');
    }

So it's define variables like below:

find_real_file.png

Execution result:

1. When Yes is selected.

find_real_file.png

2. When No is selected

find_real_file.png

 

Oh duh, im a dummy.... Thanks Hitoshi. Totally wasn't thinking about the right way. UI Policy is the way to go, thanks