Dynamically Populate a Field Based-on the Value(s) of Another Field

appstorm
Tera Contributor

I have been working on several on-change client scripts to make this work, but have so far been unsuccessful.  The task to make two fields that share the same table populate with their respective values, based-on the value of another field from the same table.

find_real_file.png

find_real_file.png

Below, is my script include.

find_real_file.png

 

How do I go about writing an on-change CS to make this work?

Thank you!

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

This is what I have defined in my PDI:

Hfind_real_file.pngHave added the fields to the Change Request form:

find_real_file.png

After flushing the cache, when I change System, Analyst and Owner automatically update.

View solution in original post

38 REPLIES 38

Prasad Pagar
Mega Sage

Hi @appstorm 

You can do this with on change client script only. No need of Script include.

Try below once. Please change fields names correctly

Onchange client script on System field.

var selected_value = g_form.getReference('system', myCallBack);

function myCallBack(selected_value) {
g_form.setValue('owner',selected_value.owner);
g_form.setValue('analyst',selected_value.analyst);
}

Hope this helps

Thank you
Prasad

Hi @appstorm 

Glad that you find it helpful.

Did my reply answer your question?

If so, can you please mark response as correct for others who may have a similar question in the future.

If not, please let us know if you need any other help

Thank you
Prasad

This is what I incorporated into my instance.

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

var selected_value = g_form.getReference('system', myCallBack);

function myCallBack(selected_value) {
g_form.setValue('owner',selected_value.u_system_owner);
g_form.setValue('analyst',selected_value.u_analyst);
}

}

Unfortunately, it does not return any values when system changes.

 

Have you added correct field names for 'system', 'owner' and 'analyst'

It should be exact logical names of your fields

This should be your field names.

Also onchange field should be System in client script.

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

var selected_value = g_form.getReference('system', myCallBack);

function myCallBack(selected_value) {
g_form.setValue('owner',selected_value.u_system_owner);
g_form.setValue('analyst',selected_value.u_analyst);
}}