How do I auto-populate one variable field, based on the selection from another?

tom_hs2
Kilo Contributor

Hi There,

 

I'm looking to auto populate a variable field on a catalog item, based on the choice selected on another variable from the same form.

Please see below the variables and what i'm trying to achieve.

find_real_file.png

Whatever is selected in 'What layer do you need access to?' i want it to then auto populate a choice in 'Group that will approve your request'.

find_real_file.png

find_real_file.png

 

find_real_file.png

find_real_file.png

the above feeds from the sys_user_group table

 

I have been looking at different Catalog client script (onChange), but as i'm not the greatest at scripting, i wanted to know if anyone has any ideas?

 

Thanks in advance.

 

 

 

 

 

8 REPLIES 8

Shane J
Tera Guru

I'm not sure how your two variables relate?  Are you saying all of the info is on the same table (sys_user_group)?

 

Here's a simple example I use to set a Location variable from a User Record that you may be able to make work for you:

 

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

var getloc = g_form.getReference('requested_for', function(gl) {
g_form.setValue('location', gl.location);
});

}

 

 

tom_hs2
Kilo Contributor

Hi Shane,

 

the first variable is a select box. When i choose an option from that select box, i wish it to auto populate a defined group into the variable below it (which feeds off the Group table)

It seems that you could use my example and just changed the fields as appropriate?

 

You have a Reference table, each record in the table that is being referenced should have a field for 'Group that will approve your request'.

ccajohnson
Kilo Sage

It sounds like you have a Select Box variable and a Reference Variable.  If you want to just fill in the reference field based upon the choice, you could put the sys_id of the expected groups into the value portion of the Choices of your Select Box variable. That way, when you select a choice, the system will just fill in that value into the Reference variable.

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