Auto populate field based on field value from another reference field

ss123
Tera Contributor

Hi everyone!

 

I need this requirement where, when I select a value in "Service offering" field, I want to auto populate the "Service" field based the Parent field of the selected "Service offering" 

Example below:

If "Service offering" = Offering v1 , then, "Offering" = SAP Enterprise Services

 

 

SabrinaSalazar_1-1666170194912.png

 

 

Hope you can help me out 🙂 Thank you in advance everyone!

 

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Write a On change client script on service offering table:-

 

Saurav11_0-1666171996141.png

 

Use the below code:-

 

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

  var caller = g_form.getReference('service_offering', setLocation);


function setLocation(caller) {
   if (caller)
       g_form.setValue('business_service', caller.parent);
}
   
}

 

Please mark my answer as correct based on Impact.

View solution in original post

7 REPLIES 7

Anubhav24
Mega Sage
Mega Sage

Hi Sabrina,

Just for one field you can use g_form.getReference functionality and then dot walk to the parent field from your service offering field and use that value to populate it in your service field.

Thanks 

ss123
Tera Contributor

i used this code in client script , but it's not auto populating the Offering field

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

  var caller = g_form.getReference('service_offering', setLocation);


function setLocation(caller) {
   if (caller)
       g_form.setValue('business_service', caller.parent);
}
   
}

 

 

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Write a On change client script on service offering table:-

 

Saurav11_0-1666171996141.png

 

Use the below code:-

 

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

  var caller = g_form.getReference('service_offering', setLocation);


function setLocation(caller) {
   if (caller)
       g_form.setValue('business_service', caller.parent);
}
   
}

 

Please mark my answer as correct based on Impact.

ss123
Tera Contributor

Hi @Saurav11 

 

Tried creating an onchange client script in incident table, per your screenshot. Added the script, but unfortunately, it's now working. Let me know If I missed something..

 

SabrinaSalazar_0-1666229689508.png

Thank you!!