Dynamic Select on Form

Product: PowerShell Universal
Version: 3.9.1

I am new to UD, and I am trying to create a simple form to automate user provisioning. The form gathers the first and last name, office and job title. However the job titles are not the same at all offices, so I would like the user to pick an office, then dynamically populate the next select box with titles for that office. Is this possible, and how would I go about it?

Here is a great blog post on just that subject. It is about a year old, but should still point you in the right direction

Dynamic Select Boxes in PowerShell Universal Dashboard (ironmansoftware.com)

Thanks, I’ll take a look. So much of PU has underlying powershell commands, it is a bit daunting to start. But that looks like what I needed.

I’d also be interested in a Dynamic Select. The linked article just syncs the choice of one select to the second, not sure the use case for that though. I’m looking for something similar to the New-UDAutocomplete -OnLoadOptions, but my issue with the AutoComplete is there is no selection until you start to type and it has something to autocomplete. I’d like to pull the Select options from a query so that User A sees A, B, C and User B would see A,B,E,F etc…

I followed the forms training video, which gave me what I was looking for. Select A is pre-populated the. Based on the option selected in A, I populate a dynamic with set of data in B.

Select A contains B, C

If B is selected then the Second select shows 1 and 2 and they f C is selected 3 and 4.

The only negative is that a dynamic select is not visible until populated. Just looks funny. But it works. Makes it more like a workflow.

Watch the video and it may work for what you are looking for as well. The video shows selecting a state and populating cities. I don’t see why you could not use a sql query or we request to populate it. By Powershell skills are not that good yet.

I could do it c# easier but Powershell has so many other benefits for system administration and our use case. c# and s just more tedious than I want

The link helped and the training video. But question, is it possible to see the dynamic select box on screen when the form loads. It is minor, just a better presentation.

As the video is layer it, it is not created until the on change, which I get. Seems like I should be able to load it, but the way the same works it is after the -onchange for previous select box. I would have to place it before that box on the form unless I am missing something or not thinking clearly.

Here’s an example of using one select to change the values of another select.


    New-UDSelect -Option {
        New-UDSelectOption -Name 'User1' -Value User1
        New-UDSelectOption -Name 'User2' -Value User2
        New-UDSelectOption -Name 'User3' -Value User3
    } -OnChange {
        $Session:CurrentUser = $EventData
        Sync-UDElement -Id 'title'
    }

    New-UDDynamic -Id 'title' -Content {
        New-UDSelect -Option {
            if ($Session:CurrentUser -eq 'User1') {
                @("A", "B", "C") | ForEach-Object {
                    New-UDSelectOption -Name $_ -Value $_
                }
            } 

            if ($Session:CurrentUser -eq 'User2') {
                @("1", "2", "3") | ForEach-Object {
                    New-UDSelectOption -Name $_ -Value $_
                }
            } 

            if ($Session:CurrentUser -eq 'User3') {
                @("X", "Y", "Z") | ForEach-Object {
                    New-UDSelectOption -Name $_ -Value $_
                }
            } 
        }
    }
1 Like