Dynamic Form in App

Hey All,

I’m trying to create a form with dynamic dropdowns in PSU/Apps (if this is not the right place, please let me know). First selection is choosing datacenter and the depending on the selection second box should populate with the clusters in that datacenter. in the backend once the first selection has been made, script should login to giving vCenter and query the clusters in the that datacenter. I try to add the login and query script on the app but that doesn’t seem to work. Any idea how can I populate form items with query?

Thanks

Product: PowerShell Universal
Version: 4.2.2

I would an -onchange for the drop down and have that invoke-psuscript using the dropdown data as a parameter. You can put the next selection in a New-UDDynamic that updates when the script is finished and has data.

I’m pretty new to this. Would you be able to provide an example code?

Oh boy… uhhh…

very rough, will need fine tuning, error handling, and a script on the back end that can use parameters, but here is a skeleton to build from.

## Populate the first selection with the datacenters
new-udselect -id "datacenter" -option {
    New-UDSelectOption -Name 'Datacenter1' -Value "Datacenter1"
    New-UDSelectOption -Name 'Datacenter2' -Value "Datacenter2"
    New-UDSelectOption -Name 'Datacenter3' -Value "Datacenter3"
} -onchange {
    ## when changing datacenters run the script to get clusters, using the datacenter as a parameter
    $datacenter = (get-udelement -id "datacenter").value
    $clusters = Invoke-PSUScript -script "get clusters.ps1" -datacenter $datacenter -wait
    ## Refresh the  second selection
    Sync-UDElement -id "dynamic"
}


new-uddynamic -id "dynamic" -content {
    ## New selection dynamically populated with the clusters from the selected datacenter
    new-udselect -id "clusters" -option {
        foreach ($c in $clusters){
            New-UDSelectOption -Name $c -value $c
        }
    }
}

It might be a better idea to have a button run the script maybe? That way if someone accidentally click the wrong selection and changes to another it’s not running a bunch of scripts on the back end.