Auto populate one variable on a Catalog item based on the value of another variable

Olaf0816
Tera Contributor

Hi!

On my test catalog item, I have created two variables, one call 'Location' and the other called 'Sitecode'.    The 'Sitecode' value should automatically update when I select a value in the 'Location' variable.

I have created a custom table.

find_real_file.png

This is my test form.

 find_real_file.png

 

 

This are my catalog item variables.

find_real_file.png

This is my client script.

find_real_file.png

Unfortunately, it's not working. What am I doing wrong? Can someone help me please?

BR

Manfred

 

7 REPLIES 7

Hi,

its a single line text variable type.

 

BR

Manfred

Hi,

what is the type of field Location? Is it a reference to your custom table? if yes then only the getReference() code would work

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Olaf0816
Tera Contributor

Hi.

This solution work for me

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

    var location = g_form.getReference('location_it', getLocationDetails);
}

function getLocationDetails(loc) {
    if (loc) {
        g_form.setValue('site_code2_it', loc.u_og_sitecode);
    }
}

BR

Manfred