How do I auto-populate one variable field, based on the selection from another?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 06:29 AM
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.
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'.
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.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 06:43 AM
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);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 07:25 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 09:59 AM
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'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 06:51 AM
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);
}