Updating variable inside button not working?

Hey guys drawing a blank on this one, maybe someone can shd some light, I have a custom object thats being output to a UDTable (computernames are then converted to UDlinks that show a modal), I want to be able to give the user the option to refresh the services table on demand, so my thinking was a button, the button fires but never updates the session variable??

[PSCustomObject]@{
                Time         = $getdatelastchecked
                Role         = $Checkroleswitch
                ComputerName = New-UDLink -Text "$server" -OnClick { Show-UDModal -Content {

                        New-UDTable -Title "Relevant Services" -Headers @("Name", "State")  -id 'table' -Endpoint {
                            $session:getServicedetails1 = $Cache:ServerServices | ? { $server -like "$($_.ComputerName)*" } 
                            $session:getServicedetails1 | Out-UDTableData -Property @("Name", "State")
                        }

                        (New-UDButton -Text "refresh services" -OnClick {                 

                                $session:getServicedetails1 = Get-ciminstance Win32_Service -ErrorAction Stop | select Name, State
                                Sync-UDElement -id 'table-tbody' -Broadcast
                            } 
                        )
                        
                    }#ENDshowmodal

                }
                ServerStatus = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $severping.Online.ToString() } 

            } 

What am I missing?

Hi @dtnyc9005

I think you are missing 'UDEndpoint ’ in your OnClick Event.

Here is my button:

 New-UDButton -Text "Sync-Data from ALL SITES" -BackgroundColor orange -FontColor white -OnClick (New-UDEndpoint -Endpoint {  
                    Show-UDToast -Message "Reloading all tables this Will take some time" -Duration 200000 
                    
                    Sync-Data_tables -data_object $data_object
                    
                    Show-UDToast -Message "Reload the Page now" -Duration 240000  

I hope that helps

Warm Regards
Maylife

Hi @dtnyc9005

This might also help.
I have also have been working with Show-UDModal.

$DB_data = Invoke-SqliteQuery -Query $Query -DataSource ( $Location + $Database )

(New-UDLink -text "Total" -OnClick  (New-UDEndpoint -Endpoint {
                            Show-UDModal -Width '95%' -Content {  
                                (New-UdGrid -Title "$($data_object[1].title)" -PageSize 50 -DefaultSortColumn "$($data_object[1]datetime_filter)"  -DefaultSortDescending -ArgumentList $DB_data -Endpoint {
                                    $ArgumentList | Out-UDGridData
                                }
                            )
                         }
                    }))

Kind Regards
Maylife

Thanks @maylife, I tried to move the endpoint and place it before the modal, like the below but same deal, the table inside the modal does not update, I thought this was going to be straight forward but im running in circles here… lolol

[PSCustomObject]@{
                Time         = $getdatelastchecked
                Role         = $Checkroleswitch
                ComputerName = (New-UDLink -Text "$server" -OnClick ( 
                        New-UDEndpoint -Endpoint {
                            Show-UDModal -Width 100% -Content {
                    
                                New-UDTable -Title "Relevant Services" -Headers @("Name", "State")  -id 'table' -Endpoint {
                                    $cache:getServicedetails1 = $Cache:ServerServices | ? { $server -like "$($_.ComputerName)*" } 
                                    $cache:getServicedetails1 | Out-UDTableData -Property @("Name", "State")
                                }
                           
                                New-UDButton -Text "refresh services" -OnClick {
                                    $cache:getServicedetails1 = Get-ciminstance Win32_Service -ErrorAction Stop | select Name, State 
                                    Sync-UDElement -id 'table-tbody' -Broadcast
                                } 
                            
                            }
                        }
                    )
                )
                ServerStatus = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $severping.Online.ToString() } 
            }

Hi @dtnyc9005

Sync-UDElement -id 'table-tbody' isn’t referencing the “New-UDEndpoint, New-UDElement or New-UDTable”

Before
New-UDTable -Title "Relevant Services" -Headers @("Name", "State") -id 'table' -Endpoint {
After
New-UDTable -Title "Relevant Services" -Headers @("Name", "State") -id 'table-tbody' -Endpoint {

Could you try matching the -IDs together?

Warm Regards
Maylife

@maylife, apparently it seems like a bug with UDtable function its expecting ‘-tbody’ when performing a sync or update, I’ve confirmed this one with a different table, the code in the button still fails to fire and I’m not sure if this is expected behavior, since I even wrapped it up in a separate endpoint.

see below github issue for the tbody in the id tag: https://github.com/ironmansoftware/universal-dashboard/issues/1332