How to autopopulate a field value based on other fields

Nisha30
Kilo Sage

Hello Experts,

I have 3 custom fields in a table (All drop down)

Field 1

Field 2

Field 3

 

I want to populate specific value when Field 2 and Field 3 are certain values (they are specific not dynamic here we have only one option)

Any client script or UI script to best achieve this 

Thanks

1 ACCEPTED SOLUTION

Rajesh Chopade1
Mega Sage

Hi @Nisha30 

you need to create two onChange client script (field 2 & field3) 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;

    // Get the values of Field 2 and Field 3
    var field2Value = g_form.getValue('field_2'); // Replace 'field_2' with the actual field name
    var field3Value = g_form.getValue('field_3'); // Replace 'field_3' with the actual field name

    // Define the specific values that trigger the change
    var specificValueField2 = 'value1'; // Replace with the specific value for Field 2
    var specificValueField3 = 'value2'; // Replace with the specific value for Field 3
    var valueToSetInField1 = 'desired_value'; // Replace with the value you want to set in Field 1

    // Check the conditions and set Field 1 accordingly
    if (field2Value === specificValueField2 && field3Value === specificValueField3) {
        g_form.setValue('field_1', valueToSetInField1); // Replace 'field_1' with the actual field name
    } else {
        g_form.setValue('field_1', ''); // Optionally clear Field 1 if conditions are not met
    }
}

 

Repeat the process to create another onChange Client Script for Field 3 with the same logic. This is necessary to ensure that changes in either field are monitored.

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

View solution in original post

8 REPLIES 8

Rajesh Chopade1
Mega Sage

Hi @Nisha30 

you need to create two onChange client script (field 2 & field3) 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;

    // Get the values of Field 2 and Field 3
    var field2Value = g_form.getValue('field_2'); // Replace 'field_2' with the actual field name
    var field3Value = g_form.getValue('field_3'); // Replace 'field_3' with the actual field name

    // Define the specific values that trigger the change
    var specificValueField2 = 'value1'; // Replace with the specific value for Field 2
    var specificValueField3 = 'value2'; // Replace with the specific value for Field 3
    var valueToSetInField1 = 'desired_value'; // Replace with the value you want to set in Field 1

    // Check the conditions and set Field 1 accordingly
    if (field2Value === specificValueField2 && field3Value === specificValueField3) {
        g_form.setValue('field_1', valueToSetInField1); // Replace 'field_1' with the actual field name
    } else {
        g_form.setValue('field_1', ''); // Optionally clear Field 1 if conditions are not met
    }
}

 

Repeat the process to create another onChange Client Script for Field 3 with the same logic. This is necessary to ensure that changes in either field are monitored.

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

Thanks @Rajesh Chopade1  for this script. 

So in client script in Field = which field has to be selected?

 

Also Field2 and Field3 can only be one specific use case because we have set that up based on dependent value in sys_choice, 

Thanks

hi

you need to create two onChange client script  for (field 2 & field3) with same script

Hi @Nisha30 

Have tried using answer provided by me?