Dynamically Update a Table after Selection

Hi,

I am planning to set a selection box to let users choose a value, and then use that value as the where clause inside a SQL query. However, it seems like not working?

The best way is to set the value after the selection, but I don’t know how to do it. so I have added a button for that.

Import-Module dbatools
$sqlserver = ‘xxx’
$database = ‘xxx’
$siteserver = ‘xxx’
$sitecode = ‘xxx’

New-UDSingleSelector -Id “stuff” -options {
@{ value = “patchserver”; label = “Server Patchlist” },
@{ value = “internalpatch”; label = “Internal Workspace” },
@{ value = “externalpatch”; label = “External Workspace” },
@{ value = “serverbaseline”; label = “Server Baseline” },
@{ value = “workstationbaseline”; label = “Workstation Baseline” }
}

New-UDButton -Text “Get Report” -OnClick {
$UDElement = Get-UDElement -id “stuff”
$value=$UDElement.Attributes.selectedOption.value
Show-UDToast -Message “You have selected $value” -Duration 5000
Sync-UDElement -Id ‘table’
}

New-UDDynamic -Id ‘table’ -Content {

this one just to test the value, but shows nothing

New-UDTypography -Text $value

$query = "
SELECT xxx
WHERE (AssignmentName = N'$value’) AND (LastComplianceMessageDesc = N’Non-compliant’)
"

$data = Invoke-DbaQuery -SqlInstance $sqlserver -Database $database -Query $query | ForEach-Object {
@{
DeviceName = $.DeviceName
LastComplianceMessageDesc = $
.LastComplianceMessageDesc
LastComplianceMessageTime = $.LastComplianceMessageTime
LastEnforcementMessageTime = $
.LastEnforcementMessageTime
LastMessage = $_.LastMessage
}
}

$columns = @(
New-UDTableColumn -Property DeviceName -Title Name
New-UDTableColumn -Property LastComplianceMessageDesc -Title Compliance
New-UDTableColumn -Property LastComplianceMessageTime -Title ReportTimeatus
New-UDTableColumn -Property LastEnforcementMessageTime -Title LastMessageTime
New-UDTableColumn -Property LastMessage -Title LastMessage
)

#New-UDStyle -Style '
#    font-size: 11px;
#    .MuiTableCell-root {
#    padding: 0px;
#}' -Content {
    New-UDTable -Data $data -Columns $columns -AutoRefresh
#} 

}

When I run, it said " An error occurred: Cannot bind argument to parameter ‘Data’ because it is null."

thanks so much!

You need to use a $Session variable in this case. try something like this.

$Session:value=$UDElement.Attributes.selectedOption.value
$query = "
SELECT xxx
WHERE (AssignmentName = N'$Session:value’) AND (LastComplianceMessageDesc = N’Non-compliant’)
"

silly me. thanks so much @adam :slight_smile: