Translation script with Manual Optionlist

Hi,

I’m trying create an option list which contains a list of ids for vmwareFolderId

Currently we have 5 vcentres which contain the same VMware Folder, but the ID is different.

Ideally I would like to add some logic so depending on what cloud has been selected then the required Vmware folder is chosen.

Apart from allowing an input for the end user to select from a list, I have not managed to get it work.

I don’t think setting VMware folders via the Morpheus GUI for each tenant is right, I have also tried to create individual inputs with the same fieldname, hidden it and set a default value, adding the custom options entry to config but get this error:

failed to create server: class java.util.ArrayList cannot be cast to class java.lang.String (java.util.ArrayList and java.lang.String are in module java.base of loader ‘bootstrap’)

I have tried to create an if statement ie if selectedcloud = devvcentre 1 push results and devcentre 2 push x results. But my if statement logic is not correct, and it just lists both items regardless of what cloud I have selected.

image

Any help appreciated?

It’s hard to pick out from the screen grab, but I think you’re going to need dependent inputs. So, one gets chosen and that triggers the next to update, and run it’s translation script, which gives you the filtered output.

You can grab the value of a previous input using “input.{fieldname}” type syntax, which will give you a value you can then use in the if statement I can see.

I have added input, however I don’t think the IF statement is correct as both are shown instead of one:

if (input.selectedCloud = (‘Devcenter1’))
{
results.push({name:data[0].name, value:data[0].value});
}
if (input.selectedCloud = (‘Devcenter2’))
{
results.push({name:data[1].name, value:data[1].value});
}

image

Hi Chopper,
Please try replacing the if condition statement with == operator .
if (input.selectedCloud == (‘Devcenter1’))
{
results.push({name:data[0].name, value:data[0].value});
}
if (input.selectedCloud == (‘Devcenter2’))
{
results.push({name:data[1].name, value:data[1].value});
}
Thanks
Mousami

Thanks.

Tried that and when I change from = to == the size goes to 0 for the results.

if I leave it just = only devcenter1 appears in the list regardless. If I enter something random in like if (input.selectedCloud == (‘xxxx’))it still triggers the push.

To troubleshoot this may be first try to print input.selectedCloud and verify that you are getting the expected value.

console.log(input.selectedCloud)

I can see in the first screenshot the value used in if statement is ‘DEVVcenter1’ and in the second post different string is used in if statement ‘Devcenter1’.

Thanks
Mousami

Thanks, I have sanitised the content. So those are not the exact vcentres listed.

I presume the console log is within the appliance?

I have looked at the content from chrome developer tools to spot what is being selected, so I’m hoping it would be the same.

Quick question. Are you on the 6.1.x branch of Morpheus or plan on upgrading to the 6.2.0 branch next month? We will be introducing a VMware folder select list within the form build to make this more native.

6.0.2 LTS version

Got it working.

I did not have real-time selected:

image

1 Like