Using Inputs To Set Other Inputs in Morpheus

A question came up as to how to use the selection of one input to set multiple other inputs in Morpheus.  The inputs were all static, so it seemed straightforward.  It was a little more complex than I thought.

The scenario is this:
Instances created will have 3 extra variables: 2b_envname, 2b_software_version, and 2b_git_branch.
If I create an instance in the Dev environment, then I want the values to be dev, 2.0, and develop respectively.
If I create and instance in the Production environment, then I want the values to be prod, 1.4, and stable.

First we'll create the 2b_envname_list option list:

Next will be the 2b_software_version_list and 2b_git_branch_list.  These will be slightly different.  The keys will match the values from 2b_envname_list.  Also, there will be a translation script to select the correct value for what you selected in the environment.  The input.<fieldname> is the fieldname you give to the first option.  In this case, it will be input.envname.  You can't use a number as the first character, so we're removing 2b_ from the field names.  Remember to check REAL TIME to make sure this gets updated whenever someone touches a selection.

For ease of copy-pasting:

if (input.envname) {
  for (var x = 0; x < data.length; x++) {
    if (data[x].name == input.envname) {
      results.push({name:data[x].name, value:data[x].value});
    }
  }
}

The 2b_git_branch_list will be basically the same, except the list name and the dataset values will be different:

Now we need to define the inputs. The 2b_envname input is simple because we want the customer to select it.  Again, the FIELD NAME can't start with a number.  We want to SHOW ON EDIT. The LABEL is just the prompt, so it can be anything.  It is REQUIRED and our option list is 2b_envname_list:

The dependent inputs are easy as well. FIELD NAME can't start with a number.  DEPENDENT FIELD will be envname.  VISIBILITY FIELD can toggle visibility, but we want this to be hidden from the customer, so we just put in false.  The LABEL is irrelevant for a hidden field, but still required.  Putting a DEFAULT VALUE of false will cause an initial selection, which we want.  Check REQUIRED and select our 2b_software_version_list list.  The 2b_git_branch input is almost exactly the same.

Now, we'll create a simple catalog item.  Use a base of Ubuntu 20.04 and set every option in the configuration wizard statically.  In the INPUTS at the bottom of the catalog item, put in the inputs we've defined:

Now, try to order the item.  It should look something like this:

Our other two inputs are hidden, but will be selected based on what we choose here.  If we choose Production and then ADD TO ORDER, we can see the values in the shopping cart:

As you can see, it's not too complicated to define many elements based on the selection of one input.  Hopefully this helps if you have a complicated instance provisioning workflow.