Struggling with Moving from -Content to -Endpoint for Dynamic Data

Hi all

Firstly, I love this product and have been playing with it for several weeks, having been reading the forums for much of today it’s great to see what a healthy community you have here! I’m a novice at best and I’m motivated to really cut my teeth on this product, I can see so many possibilities to create amazing and functional tools.

I’ve created a dashboard which has a Table i’m populating from SQL, it has several columns and that is all working fine, I’ve added a UDSelect dropdown (also from data in SQL) and now I want add/populate an additional column to my Table based on that selection, and this where I’m coming unstuck.

I’ve spent several hours now trying to wrap my head around this but I fear I’m just getting myself confused with some concepts and I would appreciate someone outlining what I need to achieve this.

I believe I need to use an Endpoint so that when the UDSelect is chosen that the Table is aware of the selection, here is my code that is using -Content

New-UDTable -Title “” -Headers @("Name ", “Parameter”, “Description”, “Setting”, “Last Updated”, “Other”) -Content {

$Data = @(Comparisons | Sort-Object -Property CommandName, CommandParameter | Where-Object { .CommandFamily -eq CommandFamily -and .Datatable -eq $Datatable } | Select-Object CommandName, CommandParameter,

CommandParameterDescription, CommandParameterType, “Setting”, LastUpdated , “Other” )

#Step through each Object in the array and make it addressable

for($i=0;$i-le $Data.length-1;$i++){

##Test for array as cant handle them yet

if ($Data[$i].CommandParameterType -ne ‘Array’){

#Update the value of Setting from the template

$Data[$i].Setting = $CompanyData.($Data[$i].CommandName).($Data[$i].CommandParameter)

}

}

$Data | Out-UDTableData -Property @(“CommandName”, “CommandParameter”, “CommandParameterDescription”, “Setting”, “LastUpdated” , “Other”)

$Data = $null

}

The first part of the puzzle for me is to simply try and get the existing data showing in my table using -EndPoint instead of -Content, but changing to -Endpoint results in a blank table.

If I insert data manually here using PSCustomObject then it appears, after more digging I think this is related to the Runspaces being different for variables I’ve put in Memory, in the above you can see $Comparisons, it contains test data I’ve manually called from SQL.

I tried adding this $Cache:Comparisons = $Comparisons to the top of my script, I’ve added a button to test and it shows a Datatable.row so I know it’s seeing the data at this stage:

New-UDButton -Text “Check Session Info” -OnClick {
Show-UDToast -Message “$Cache:Comparisons”
}

Then updated the UDTable script block as follows:

New-UDTable -Title “” -Headers @("Name ", “Parameter”, “Description”, “Setting”, “Last Updated”, “Other”) -Endpoint {
$Data = @(Cache:Comparisons | Sort-Object -Property CommandName, CommandParameter | Where-Object { .CommandFamily -eq CommandFamily -and .Datatable -eq $Datatable } | Select-Object CommandName, CommandParameter,
CommandParameterDescription, CommandParameterType, “Setting”, LastUpdated , “Other” )
Step through each Object in the array and make it addressable
for($i=0;$i-le $Data.length-1;$i++){
##Test for array as cant handle them yet
if ($Data[$i].CommandParameterType -ne ‘Array’){
#Update the value of Setting from the template
$Data[$i].Setting = $CompanyData.($Data[$i].CommandName).($Data[$i].CommandParameter)
}
}
$Data | Out-UDTableData -Property @(“CommandName”, “CommandParameter”, “CommandParameterDescription”, “Setting”, “LastUpdated” , “Other”)
$Data = $null
}

But my table is still Empty :frowning: . I tried this too: New-UDEndpointInitialization -Variable $Comparisons but same result. I’m more then happy to read and research further but just feel I’m missing a fundamental concept, anyone able to give me some pointers?

Many thanks for taking the time to read my novel!

So is the output you are trying to display being redirected to a dynamic page?

$GameHistory = New-UDPage -URL "/Ubetcha/GameHistory" -EndPoint {

Maybe reviewing several examples of using dynamic pages will unblock you.

Hello @MaCCa yes indeed you are correct you can build amazing things from this module, only your imagination holds you back…and some coding concepts…I have written several blogs here:- https://psdevuk.github.io/ud-flix/ that cover using SQL and UD, and Content Vs Endpoint…as for analyzing the SQL data I have found the pivot component to give perfect results to display the data in a manner of ways. This is also on my blog site…happy reading let me know if you need more info :crazy_face:
P.S Also got a fully working Dashboard linked to SQL here:- https://github.com/psDevUK/psUniversalDashboard which shows how to load cache data session data and T-SQL query data to a dashboard…

@cadayton

What i was hoping to achieve was having the UDSelect and the Table data all on the same page, when you select an entry, the table below it would update data in a column, so the user can compare their settings (already loaded) with that of a template (from the UDSelect). I will read more on Dynamic pages.

@psDevUK
Fantastic blog and information! Your dashboard project looks just like what i need to reference, thank you for all the info :slight_smile:

1 Like

I got it working! Thanks for everyone’s help :slight_smile:

I did have another problem with Sync-UDElement , I was trying to use it to reload the page I was on but it didn’t seem to work, is this a limitation? I found a thread on Reddit which allowed me to wrap the code I wanted inside a New-UDElement and Sync this instead, turns out it was a better design that way as it loads much quicker!

Maybe this is what you are searching in order to reload the whole page (haven’t ever used this myself).

@augustin.ziegler Thanks for the link, may come in handy in other parts of my dashboard :call_me_hand: :call_me_hand:

1 Like