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

Abhishek_Thakur
Mega Sage

Hello @Nisha30 ,

You can refer the below script. You just need to change the field name.

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

   //Type appropriate comment here, and begin script below
   alert('SAR1');
   if (isLoading || newValue == '') {
   alert('SAR2');
        g_form.clearOptions('e_voucher_brand', '');
        return;
    }
    if (newValue == 'E-Commerce') {
        alert('SAR3');
        g_form.removeOption('e_voucher_brand', 'Lifestyle');
        g_form.removeOption('e_voucher_brand', 'Allen Solly');
        g_form.removeOption('e_voucher_brand', 'Zomato');
        g_form.removeOption('e_voucher_brand', 'Swiggy');
        g_form.removeOption('e_voucher_brand', 'Puma');
        g_form.removeOption('e_voucher_brand', 'Adidas');
        g_form.removeOption('e_voucher_brand', 'Nike');
        g_form.addOption('e_voucher_brand', 'Flipkart', 'Flipkart');
        g_form.addOption('e_voucher_brand', 'Amazon', 'Amazon');
        g_form.addOption('e_voucher_brand', 'Myntra', 'Myntra');

    }
   
    else if (newValue == 'Shopping') {
        alert('SAR4');
        g_form.removeOption('e_voucher_brand', 'Flipkart');
        g_form.removeOption('e_voucher_brand', 'Amazon');
        g_form.removeOption('e_voucher_brand', 'Myntra');
        g_form.removeOption('e_voucher_brand', 'Zomato');
        g_form.removeOption('e_voucher_brand', 'Swiggy');
        g_form.removeOption('e_voucher_brand', 'Puma');
        g_form.removeOption('e_voucher_brand', 'Adidas');
        g_form.removeOption('e_voucher_brand', 'Nike');
        g_form.addOption('e_voucher_brand', 'Lifestyle', 'Lifestyle');
        g_form.addOption('e_voucher_brand', 'Allen Solly', 'Allen Solly');

    }

    else if (newValue == 'Sports Wear') {
        alert('SAR5');
        g_form.removeOption('e_voucher_brand', 'Lifestyle');
        g_form.removeOption('e_voucher_brand', 'Allen Solly');
        g_form.removeOption('e_voucher_brand', 'Zomato');
        g_form.removeOption('e_voucher_brand', 'Swiggy');
        g_form.removeOption('e_voucher_brand', 'Flipkart');
        g_form.removeOption('e_voucher_brand', 'Amazon');
        g_form.removeOption('e_voucher_brand', 'Myntra');
        g_form.addOption('e_voucher_brand', 'Puma', 'Puma');
        g_form.addOption('e_voucher_brand', 'Adidas', 'Adidas');
        g_form.addOption('e_voucher_brand', 'Nike', 'Nike');
    }
   
    else if (newValue == 'Food Delivery') {
        alert('SAR6');
        g_form.removeOption('e_voucher_brand', 'Flipkart');
        g_form.removeOption('e_voucher_brand', 'Amazon');
        g_form.removeOption('e_voucher_brand', 'Myntra');
        g_form.removeOption('e_voucher_brand', 'Lifestyle');
        g_form.removeOption('e_voucher_brand', 'Allen Solly');
        g_form.removeOption('e_voucher_brand', 'Puma');
        g_form.removeOption('e_voucher_brand', 'Adidas');
        g_form.removeOption('e_voucher_brand', 'Nike');
        g_form.addOption('e_voucher_brand', 'Zomato', 'Zomato');
        g_form.addOption('e_voucher_brand', 'Swiggy', 'Swiggy');
    }
}

Replace the option with your filed values.

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

HI @Abhishek_Thakur let me give what exactly is my system

 

Nisha30_0-1726755538775.png

here

Field 1 = VM Size

Field 2 = Memory Range  

Field 3 = CPU Range

 

CPU range drop down is dependent on Memory Range (so similar to Incident Category/Subcategory). Example : MemoryRange as shown above is 8-16GB , CPU Range can only be 2-4  and no other options.

 

Now based on above example MemoryRange and CPURange can only be the above case. Based on these both values VMSize should be populated 

Hello @Nisha30 ,

Here, you don't need any script. Simply you can configure the dependent field easily. Attaching the snapshot for your reference.

Dictionary entry1.png

Open the dictionary entry of CPU range and make it too dependent on Field2 (Memory Range).

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

HI @Abhishek_Thakur i have done the same way . The only thing is i want to populate VM Size based on these two fields