I have some troubles in Options lists in terms of visibility field

I have created a two option lists in Morpheus.

Availability Zone:(fieldname:az)
us-east-1b, us-east-1c, us-east-1d

Operating System: (fieldname:os)
RHEL8
AL2
Windows

I am trying to make a relational dropdown between availability zone and OS here.
When user chooses US-east-1b then I will have to display RHEL8, AL2.

If User chooses us-east-1c, then I will have to display just Windows.

What is the condition I need to pass in visibility field of Operating system which can help me with value based drop down ?

Will be helpful if you can help me with syntax.

Hi Venkat,
You can do this in 2 ways.
First way - If your OS data can be hosted on a JSON source, you can use the REST option list and translation script. You would need to configure you JSON data as follows:

[{
“id”: 1,
“os”: “RHEL8”,
“az”: “us-east-1b”
}, {
“id”: 2,
“os”: “AL2”,
“az”: “us-east-1b”
}, {
“id”: 3,
“os”: “Windows”,
“az”: “us-east-1c”
}]

You could then use the following translation script on the operating system list:

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

Second way - This is more complex and requires more java scripting knowledge. This approach uses the manual option list and a mapper variable.
Create a manual option list for operating system.
In the dataset field, enter [ ] to create an empty list.
Then in the translation script, you would have to create a java script similar to this which generates the option list using the results.push method:

let mapperKey = input.az;
let mapper = {
“us-east-1b”: [
{“name”:“RHEL8”,“value”:“R8”},
{“name”:“AL2”,“value”:“A2”}
],
“us-east-1c”: [
{“name”:“Windows”,“value”:“WIN”}
],
“us-east-1d”: [
{“name”:“RHEL8”,“value”:“R8”},
{“name”:“AL2”,“value”:“A2”},
{“name”:“Windows”,“value”:“WIN”}
]
};

if (mapperKey in mapper) {
let localOptions = mapper[mapperKey];
for (let i = 0; i < localOptions.length; i++) {
results.push({“name”: localOptions[i].name, “value”: localOptions[i].value });
}
}

NOTE: In the above example, the availability input has the fieldname set to az. You also need to make the operating system input dependent on the availability zone input.

@pjones I have tried the the syntax like mentioned above, however, I am not seeing any options being listed in my catalog for OS list. Wanted to review the Syntax If I have missed anything specific:

Data set:
[{“os”:“RHEL8”,“az”:“us-east-1b”},{“os”:“AL2”,“az”:“us-east-1b”},{“os”:“Windows”,“az”:“us-east-1c”}]

Translation Script:
console.log(input.az)
for(var y=0;y < data.length; y++) {
if (input.az == data[y].az) {
results.push({“name”: data[y].os,“value”: data[y].os});
}}


Catalog Page:
Drop down results as no Option found:
image

Hi Venkat,
You will need to make sure that you set the dependent field setting on the input for the operating systems.
I’ve set this up in my lab and made a recording to show you it working - Screen Capture on 2022-10-23 at 10-47-45.mp4 - Droplr

Thanks
Pete

2 Likes

Thanks @pjones for the wonderful explanation. It is working as expected!

1 Like