UD 3 - Beta7 - Set custom elements based on selection

Good afternoon,
I’m currently continuing my journey through code refactor of my dashboard in UD 2.x to UD 3 in the PSUniversal setup.

Back on UD 2.x, I had sections setup on pages that would update/change depending on selections. Attached is a gif example, selecting the radio button option would create/update a secondary input box for this function.

I accomplished this in 2.x by creating a UDElement with an ID and a blank -endpoint. I then used the on-change functionality of the radio button to do a set-udelement on the ID i established for the box. And like magic, box changes depending on the selection!

However, when trying this on my version 3 rewrite, I’m getting nothing out of it. Anyone come across this and provide some guidance?

Thanks!

Try New-UDDynamic with Sync-UDelement

I had forgotten about the UDDynamic setup. However looking at Sync-UDElement, and even Set-UDElement, it doesn’t have a content parameter, only ID and Broadcast. I’m unclear what Broadcast does, but just from some initial testing i’m not seeing any results trying this approach.

I had to break from working on this, but I’m back on it and still fighting the overall issue.
I’m seeing the set-elementy has a -properties functionality now that expects a hashtable. I’m wondering if there is any ability to setup the entirety of what would normally be in the -content {} of something like Paper or Card and how that would look from a formatting perspective. I feel like i’m just missing the proper coded way to execute this update of the element itself.

Finding the exact same issue and it’s driving me nuts!

Hi @dcherry88,

have you try to put your control in the New-UDDynamic ? for instance I’m using the following code to update status on various actions using New-UDDynamic with Sync-UDElement and Cache or Session variable:

New-UDDynamic -Content {
    New-UDList -Content {
        New-UDListItem -Label 'AD Object Creation'      -Icon (Get-StatusIcon -Job $Session:ADMachineCreationJob)    -SubTitle ([string]::format("{0} - {1}", $Session:ADMachineCreationJob.Status,$Session:ADMachineCreationJob.Id))
        New-UDListItem -Label 'AD Object Move'          -Icon (Get-StatusIcon -Job $Session:ADMachineMoveJob)        -SubTitle ([string]::format("{0} - {1}", $Session:ADMachineMoveJob.Status,$Session:ADMachineMoveJob.Id))
        New-UDListItem -Label 'HV Object Creation'      -Icon (Get-StatusIcon -Job $Session:HVMachineCreationJob)    -SubTitle ([string]::format("{0} - {1}", $Session:HVMachineCreationJob.Status,$Session:HVMachineCreationJob.Id))
        New-UDListItem -Label 'HV Object Entitlement'   -Icon (Get-StatusIcon -Job $Session:HVMachineEntitlementJob) -SubTitle ([string]::format("{0} - {1}", $Session:HVMachineEntitlementJob.Status,$Session:HVMachineEntitlementJob.Id))
    }  
} -Id 'vm-operations-status-list'

everytime a change occurs to UA jobs related to these actions, I run a Sync-UDElement or multiple with the ID of the UDDynamic and it update the whole content of my UDList. You can use the followin syntax to sync UDElement:

Sync-UDElement -Id ‘my-id-from-UDDynamic1’
or
@(‘my-id-from-UDDynamic1’,‘my-id-from-UDDynamic2’,‘my-id-from-UDDynamic3’) | Sync-UDElement

so far it did the trick for me updating table / list / typography and so on.

let me know if I may help, hope this example helped a little

If I’m understanding your code examples here, you are establishing the object with $session:vars that represent data from different job information. When that data gets updated in the $session:var you are then running Sync-UDElement. Is this correct?

If so, I’m not sure how it would work into this scenario I have. Or if it does, I’m still not understanding the best way code would be setup. It might be easier to map out the old UD 2.x code to understand where I’m trying to go.

I initially declared a UD element that was just empty, in the location i wanted the box based off the UDRow/UDColumn grid setup

New-UDElement -id "BUModify" -Tag "BUModify" -Endpoint {}

Then, on the code for the radio buttons I would dictate out what I wanted the code in that endpoint to become utilizing set-udelement. So each time a differnet radio is hit, you are re-setting the contents of the UDElement as well as changing the endpoint action based off the input.

New-UDCard -Title "Make Changes" -Content {
    New-UDRadio -Label 'Modify' -Group 'grp1' -OnChange {
        Set-UDElement -Id "BUModify" -Content {
            New-UDInput -Content {
                New-UDInputField -Type select -Name "BU_ID" -Values $Cache:BUQuery.bu_ID
                New-UDInputField -Type textbox -Name "NewName" -Placeholder "New Name"
            } -Endpoint {
                param($BU_ID,$NewName)
                Invoke-Sqlcmd -ServerInstance $Cache:configdata.siteconfigdata.configsqldbserver -Database $Cache:configdata.siteconfigdata.configsqldbname -Query "querydatahere"
                Show-UDToast -Title "Entry Updated" -Message "$BU_ID has been updated with name $NewName" -Position center -CloseOnClick -duration 15000
            }
        }
    }
    New-UDRadio -Label "Add" -Group 'grp1' -OnChange {
        Set-UDElement -Id "BUModify" -Content {
            New-UDInput -Content {
                New-UDInputField -Type textbox -Name "BUName" -Placeholder "New BU Name"
            } -Endpoint {
                param($BUName)
                if($Cache:BUQuery.bu_name -contains $BUName){
                    Show-UDToast -Title "Entry Exists" -Message "The name $BUName already exists in the DB."
                }else{
                    Invoke-Sqlcmd -ServerInstance $Cache:configdata.siteconfigdata.configsqldbserver -Database $Cache:configdata.siteconfigdata.configsqldbname -Query "querydatahere"
                    Show-UDToast -Title "Entry Added" -Message "$BUName has been added to the DB" -Position center -CloseOnClick -duration 15000
                }
            }
        }
    }
    New-UDRadio -Label "Remove" -Group 'grp1' -OnChange {
        Set-UDElement -Id "BUModify" -Content {
            New-UDInput -Content {
                New-UDInputField -Type select -Name "BU_ID" -Values $Cache:BUQuery.bu_ID
            } -Endpoint {
                param($BU_ID)
                Invoke-Sqlcmd -ServerInstance $Cache:configdata.siteconfigdata.configsqldbserver -Database $Cache:configdata.siteconfigdata.configsqldbname -Query "querydatahere"
                Show-UDToast -Title "Entry Removed" -Message "$BU_ID has been removed from DB" -Position center -CloseOnClick -duration 15000
            }
        }
    }
}

So if I take this thought process into UD 3.x, I have been attempting to do an initial UDDynamic (even trying auto-refresh options) with just basic data like a new card and some dummy data for the sake of the test. Then I was attempting to use Sync-UDElement to change the content section just like I did in the UD 2.x example.

New-UDDynamic -Id 'dyncontent' -autorefresh -AutoRefreshInterval 5 -Content {
    New-UDPaper  -content {
        New-UDTypography -Text "stuff"
    }
}