Need a sorted Morpheus API Option List for Networks

Hi, we want to sort output from a Morpheus API Option List for “Networks”. The Option List is filled, but not sorted alphabetically. I have tried with following Translation Script:

for(var i=0;i < data.length; i++) {
  results.push({name: data[i].name,value:data[i].name});
}
results = results.sort((a, b) => {
  if (a.name.toUpperCase() < b.name.toUpperCase()) {
    return -1;
  }
});

But it’s not working as expected. Can anyone help with this?

Thanks in advance!

Is this a specific cloud? I’m not seeing the same behavior. I use the following:

translation script:

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

request script:

if (input.targetCloud && input.targetGroup) {
  results.siteId = input.targetGroup
  results.zoneId = input.targetCloud
}

This results in:

image

It is possible it’s A-Z per vSwitch

Thanks for your reply. It’s an on-prem vSphere Cloud. Unfortunately, I have not showed you our Request Script, which looks like that:

request script:

if (input.f_VC_Clouds_ALL && input.f_VC_ResourcePool_ALL) {
    results.cloudId = input.f_VC_Clouds_ALL
    results.poolId = input.f_VC_ResourcePool_ALL
}

In the Catalog Item we must limit Networks to user selected Resource Pools. In fact, there are several distributed vSwitches behind it. Nevertheless, I thought the list, contained in ‘data’ is sorted in the translation script as a whole and not by distributed vSwitches. This should have no influence, or do I see it wrong? ‘data’ is a Java object, and it should be sorted as a whole, via translation script, or am I wrong?

example output:

image
image

Question:
Is it some how possible, to print out the raw content (data) the Morpheus API call receives?

So I added another portgroup and it has Apple and VSAN. They both appear in the correct alphabetical order based on the scripts I have listed above.

image

Note, I’m not trying to do any sort of custom sorting in my translation and it just works here.

As for the raw data, you can see some of it inspecting the browser page:
image

There are also debugs that would output all available data for the calls, though our documentation lists the data that returns/is filterable for option lists here

This is helpful information. I do not know why the list is not issued alphabetically in our environment. But in the meantime, I have found a way by applying the following translation script. It contains a different sorting algorithm than my first script. Now it works perfectly.

working translation script:

for(var x=0;x < data.length; x++) {
  results.push({name: data[x].name,value:data[x].name});
}
results = results.sort((a, b) => a.name.localeCompare(b.name));

Many thanks for your support!

Glad it’s all working now. Quick question, what version are you on? I know earlier this year we updated a few of the select lists for better sorting.

A few weeks ago, we upgraded from V. 5.3.3 to V. 5.4.10. Perhaps this really has an influence… :wink: