Updating table row/cell values on demand button click?

Hi all, currently have a service that hosted across several servers that needs to be frequently polled for status, put together schedule endpoint that runs and populates a table below with out issues, I want to be able to give the users the ability to run the function on demand on come back and update the CallTime and Response values for that specific server whenever button is triggered , does anyone have any ideas?, probably not thinking straight… I would use an -id on the new-udendpoints(Typo, meant UDElement) but that will change it for all items in the table.

$ScheduleSoapCalls = New-UDEndpointSchedule -Every 15 -Minute`
$EndpointSoapCalls = New-UDEndpoint -Schedule $ScheduleSoapCalls -Endpoint {
$cache:SoapCallsDate = (get-date -Format t)

$SoapCalls = $servers |Get-SoapCall

$cache:Collection = @(

    foreach ($psitem in $SoapCalls) {

            ComputerName = $($psitem.ComputerName)
            URL          = $psitem.url
            Response     = New-UDElement -Tag 'div' -Content { $psitem.Response } 
            CallTime     = New-UDElement -Tag 'div' -Content { $psitem.calltime } 
            Action       = (New-UDButton -Text "Refresh Call Request" -OnClick { $psitem.computername |Get-SoapCall ; Set-UDElement -Content {???} })



@dtnyc9005 This is my guess as to what I think you might be trying to achieve in the code block you listed. I could be off and like I always say, no promises.

Try this:

$SoapCalls = $servers | Get-SoapCall

Foreach ($item in $SoapCalls) {

    New-UDCard -Title $item.ComputerName -Content {
        New-UDLink -text "Link" -Url $item.url
        New-UDParagraph -Text $item.Response
        New-UDParagraph -Text $item.Callback
        New-UDButton -IconAlignment right -Text "Refresh" -OnClick (New-UDEndpoint -Endpoint {
           $ArgumentList[0] | Get-SoapCall } -ArgumentList @($item.ComputerName))

A few things…regardless if I totally miss the mark on this or not, you want to avoid using the automatic variable $PSItem in a foreach statement (unless the rules have changed and I need to get with the times). That variable is the same as $_ and is the current pipeline object that is generally reserved for referencing items in a collection that are streamed “one-at-a-time” into cmdlets after the pipeline.

Using the $PSItem would be acceptable if the line foreach ($PSItem in $SoapCalls) { was changed to $SoapCalls | Foreach-Object {... but that’s always been my understanding since it. I changed the variable to $item for the Foreach Statement.

Like I said, I took a stab at it so let me know what you think.

Edit: I know I am focusing on this a lot but you can also use the $_ or $PSItem automatic variable in a switch statement when referencing the testing-value in the condition block:

$int = 555
 switch ( $int ) {
        { $PSItem -le 365 }   { 'alert' }
        { (($PSItem -gt 365) -and ($PSItem -le 720)) } { 'warning' }
        { $PSItem -gt 720 } { 'good' }

I took this from one of scripts dealing with certificates and expiration dates. Just throwing that out there.

Hey @nicoeat614 thanks for the pointers and apologize for the late response as I was under the weather for the past 2 or so weeks, anyway I did manage to get this going but think there’s some serialization issue after the object is changed on the custom object, I think it has to do with cache variable never actually updating on the backend just the front end table component.