Server-Side Table Error in Out-UDTableData

I have dashboard set up that shows a table of values that pulls from SQL. It shows all the data correctly and renders everything correctly… When I view the dashboard, I keep getting an error (now in the form of a Toast Message with 2.1), that says "

Cannot bind argument to parameter ‘InputObject’ because it is null"

The Dashboard log returns the following:

[2021-07-01T16:19:30.9825398Z] An error occurred: Cannot bind argument to parameter ‘InputObject’ because it is null.
Endpoint: HardwareDevices
Session: d28405c4-b748-45f9-8d0f-a5fbc37c3a59
Endpoint Start Line: 13
Endpoint End Line: 184
Stack Trace: at New-UDTable, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 4504
at , : line 67

That line is the line that has the following line of code:

$AllHardware | Out-UDTableData -Page $TableData.Page -TotalCount $CountHW.count -Properties $TableData.Properties

I’ve verified that my “$AllHardware” variable contains the data as it shows up on the table that is displayed. And i’ve also verified that the count is retrieving the right amount. The other two items comes from the json $Body…

Here is the whole table code:

New-UDTable -Title ‘Computer Hardware’ -ShowSelection -Dense -LoadData {
$TableData = ConvertFrom-Json $Body
$OrderBy = $TableData.orderBy.field
If ($OrderBy -eq $null){
$OrderBy = ‘HostName’
$OrderDirection = $TableData.orderDirection
If ($OrderDirection -eq $null){
$OrderDirection = “asc”

    $Where = ""
    If ($TableData.Filters){
        $Where = "WHERE "
        ForEach($filter in $TableData.Filters){
            $Where += $ + " LIKE '%" + $filter.value + "%' AND "
        $Where += " 1 = 1"
    $PageSize = $TableData.PageSize
    # Calculate the number of rows to skip
    $Offset = $TableData.Page * $PageSize
    $CountHW = Invoke-Sqlcmd -ServerInstance SQLSERVER -Database DATABASE -Credential $Credential -Query "Select COUNT(*) as count from dbo.Hardware $WHERE" 
        $AllHardware = @()
        $HardwareData = Invoke-Sqlcmd -ServerInstance SQLSERVER -Database DATABASE -Credential $Credential -Query "Select a.Id,SerialNumber,TargetOU,HostName,TaskSequenceID,ApplicationProfileName,a.applicationProfileID,a.Notes from dbo.Hardware as a left join dbo.ApplicationProfile as b on b.Id = a.ApplicationProfileID $WHERE ORDER BY $OrderBy $OrderDirection OFFSET $Offset ROWS FETCH NEXT $PageSize ROWS ONLY"
        ForEach ($HardwareItem in $HardwareData){
            $TempID = $HardwareItem.TaskSequenceID
            $TempAppID = $HardwareItem.ApplicationProfileID
            $AllHardware += @{
                HostName = $HardwareItem.HostName
                SerialNumber = $HardwareItem.SerialNumber
                TaskSequenceName = $($TaskSequences | Where-Object {$_.AdvertisementID -eq $TempID}).PackageName
                ApplicationProfileName = $($ApplicationProfiles | Where-Object {$_.ID -eq $TempAppID}).ApplicationProfileName
                TaskSequenceId = $TempID
                ApplicationProfileId = $TempAppID
                HardwareID = $HardwareItem.Id
                TargetOU = $HardwareItem.TargetOU
                Notes = $HardwareItem.Notes
        $AllHardware | Out-UDTableData -Page $TableData.Page -TotalCount $CountHW.count -Properties $TableData.Properties
    } -Columns @(
        New-UDTableColumn -Property 'HostName' -Title 'Computer Name' -Sort -Filter -DefaultSortColumn -IncludeInExport
        New-UDTableColumn -Property 'SerialNumber' -Title 'Serial Number' -Sort -Filter -IncludeInExport
        New-UDTableColumn -Property 'TargetOU' -Title 'Destination OU' -Sort -Filter -IncludeInExport
        New-UDTableColumn -Property 'TaskSequenceName' -Title 'Task Sequence' -Sort -Filter -IncludeInExport
        New-UDTableColumn -Property 'ApplicationProfileName' -Title 'Application Profile' -Sort -Filter -IncludeInExport
        New-UDTableColumn -Property 'HardwareID' -Title 'Action' -Render {
            New-UDButton -Icon (New-UDIcon -Icon edit) -OnClick {
                Show-UDModal -Persistent -FullWidth -MaxWidth 'md' -Content {
                    New-UDTypography -Text "Edit Hardware Entry" -variant 'h4'
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDTextBox -Id 'txtHardwareID' -Disabled -Value $Eventdata.HardwareID
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDTextBox -Id 'txtHostName' -Label 'Computer Name' -Value $Eventdata.HostName
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDTextBox -Id 'txtSerialNumber' -Label 'Serial Number' -Value $EventData.SerialNumber
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDTextBox -Id 'txtOU' -Label 'Destination OU' -FulLWidth -Value $EventData.TargetOU
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDSelect -Id 'comboTaskSequences' -Label 'Task Sequence' -DefaultValue $EventData.TaskSequenceID -Option {
                        $AvailableTaskSequences = $TaskSequences | Sort-Object -Property PackageName
                        ForEach ($TaskSequence in $AvailableTaskSequences){
                            New-UDSelectOption -Name $TaskSequence.PackageName -Value $TaskSequence.AdvertisementID
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDSelect -Id 'comboApplicationProfile' -Label 'Application Profile' -DefaultValue $EventData.ApplicationProfileID -Option {
                        $AllApplicationProfiles = $ApplicationProfiles | Sort-Object -Property ApplicationProfileName
                        ForEach ($Profile in $AllApplicationProfiles) {
                            New-UDSelectOption -Name $Profile.ApplicationProfileName -Value $Profile.ID
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDTextBox -Id 'txtNotes' -Label 'Notes' -Value $EventData.Notes -Multiline -Rows 4 -FullWidth
                } -Footer {
                    New-UDButton -Text "Update Computer" -Icon (New-UDIcon -Icon plus_square -Color 'green' -Size 'lg') -OnClick {
                        $NewHardwareID = $(Get-UDElement -Id 'txtHardwareID').Value
                        $NewHostName1 = $(Get-UDElement -Id 'txtHostName').Value
                        $NewTargetOU1 = $(Get-UDElement -Id 'txtOU').Value
                        $NewSerialNumber1 = $(Get-UDElement -Id 'txtSerialNumber').Value
                        $NewTaskSequence1 = $(Get-UDElement -Id 'comboTaskSequences').Value
                        If ($NewTaskSequence1 -eq $null -or $NewTaskSequence1 -eq '') {
                            $NewTaskSequence1 = $($EventData.TaskSequenceID)
                        $NewApplicationProfile1 = $(Get-UDElement -Id 'comboApplicationProfile').Value
                        If ($NewApplicationProfile1 -eq $null -or $NewApplicationProfile1 -eq '') {
                            $NewApplicationProfile1 = $EventData.ApplicationProfileID
                        $NewNotes1 = $(Get-UDElement -Id 'txtNotes').Value
                        If ($NewHostName1 -eq $null -or $NewHostName1 -eq ''){
                            Show-UDToast -Message "Hostname must not be empty." -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                        } elseif ($NewHostName1.Length -gt 15){
                            Show-UDToast -Message "Hostname must not be more than 15 characters." -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                        } elseif ($NewSerialNumber1 -eq $null -or $NewSerialNumber1 -eq '') {
                            Show-UDToast -Message "Serial Number must not be empty." -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                        } elseif ($NewTargetOU1 -eq $null -or $NewTargetOU1 -eq '') {
                            Show-UDToast -Message "Destination OU must not be empty." -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                        } elseif ((Invoke-RestMethod "$NewTargetOU1") -eq $False) {
                            Show-UDToast -Message "Destination OU does not exist, please specify an existing OU." -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                        } elseif ($NewTaskSequence11 -eq 0) {
                            Show-UDToast -Message "You must choose an Task Sequence" -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                        } elseif ($NewApplicationProfile1 -eq 0) {
                            Show-UDToast -Message "You must choose an Application Profile" -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                        } else {
                            Try {
                                #Show-UDToast "TaskSequenceID = '$NewTaskSequence1', ApplicationProfileID = $NewApplicationProfile1" -Duration 60000 -Position 'bottomCenter'
                                Invoke-Sqlcmd -ServerInstance SQLSERVER -Database DATABASE -Credential $Credential -Query "UPDATE dbo.Hardware 
                                SET SerialNumber = '$($NewSerialNumber1)', HostName = '$($NewHostName1)', TargetOU = '$($NewTargetOU1)', TaskSequenceID = '$($NewTaskSequence1)', ApplicationProfileID = $($NewApplicationProfile1), Notes = '$($NewNotes1)', UpdateUser = '$User', UpdateDate = '$(Get-Date)' 
                                WHERE Id = $($NewHardwareID)" -ErrorAction stop
                                #Show-UDToast -Message $TestSQL -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                                Sync-UDElement -Id 'HardwareDevices'
                            } catch {
                                Show-UDToast -Message "Failed to update Computer Object" -Duration 20000 -MessageColor 'red' -Position 'bottomCenter'
                    New-UDButton -Text "Close" -Icon (New-UDIcon -Icon times_circle -Color 'red' -Size 'lg') -OnClick { 
            New-UDButton -Icon (New-UDIcon -Icon trash) -OnClick {
                Show-UDModal -Content { 
                    New-UDTypography -Text "Are you sure you wish to delete this entry?" -variant 'h5'
                    New-UDElement -tag 'p' # This adds a blank line
                    New-UDTypography -Text "$($EventData.HostName)" -variant 'h5'
                } -footer {
                    New-UDButton -Text "YES" -Icon (New-UDIcon -Icon check_circle -Color 'green' -Size 'lg') -OnClick {
                        Invoke-Sqlcmd -ServerInstance SQLSERVER -Database DATBASE -Credential $Credential -Query "DELETE FROM dbo.Hardware WHERE Id = $($EventData.HardwareId)"
                        Show-UDToast -Message "You have successfully deleted $($EventData.HostName)"
                    New-UDButton -Text "NO" -Icon (New-UDIcon -Icon times_circle -Color 'red' -Size 'lg') -OnClick {
        ) -showSort -showPagination -showFilter -showExport -OnRowSelection {
            $Item = $EventData
            #$Item | Export-CSV C:\temp\hardwaretesting.csv
            If ($($Item.Selected) -eq $true){
                #Show-UDToast -Message "$($Item.SerialNumber)"
                $row = $table.NewRow()
                $row.HardwareID = "$($Item.SerialNumber)"
            } else {
                $table.Select("HardwareID = '" + $($Item.SerialNumber) + "'").Delete()

Any help would be greatly appreciated.

Thank you.

Product: PowerShell Universal
Version: 2.1.0

I added a new flag (-DisableErrorToast) to 2.1.2 to avoid this from popping up if you don’t want it to.

The error is because at some point the data is null that is being passed to the table but I’ve seen a lot of people reporting this so I’m not sure why it’s happening exactly. It seems in most cases, when checked, the data isn’t actually null and the table works.

Will that be on the New-UDTable or the New-UDPage, or which function? Or will it be available for all of them?

It’s going to be a flag on the dashboard so it stops it for the entire thing.

1 Like

@adam - I have been getting that same message ever since I updated to 2.1.0.
Prior to this, I seen no errors. I have a page on a dashboard that I allow users to query a database with a couple of date pickers. There is different queries they can run by selecting a radio button and then correct form will appear for them. If I click all of the radio buttons I will get the initial error but then next load I don’t as long as I don’t clear my cache from what I can tell.

If you want to disable this message, you can disable error toasts in the dashboards.ps1: Dashboards - PowerShell Universal

You’ll need at least version 2.1.2

1 Like

@adam - Thank you, I did just update to 2.1.2. I was not sure if I was doing something wrong to cause the error message to appear. I will tinker with my code, I am hoping to fix what is causing the error to be generated.

Cool. Yeah I think a lot of errors like this went unnoticed until the error toast was (re)-added in 2.1. It’s how UDv2.9 used to work. I didn’t realize the toast would pop up on so many peoples’ environments. :grimacing:

1 Like

@adam - I was able to track it down for my script! I definitely appreciate the error toast, helps me realize if something may not be laid out exactly as it should be. In my case, I was able to eliminate 3 of the 4 messages by redoing my -OnValidate section. :slight_smile:

1 Like

That’s great to hear! Glad you were able to solve it!

1 Like

Hey @Adam, Related to the error toast, I am assuming I am getting this because something has not loaded yet. What is the best way to perform the validation on this? This is my switch statement in -OnValidate section:

        Switch ($value) {
             'QRange' {
                $dateFrom = (Get-Date $($EventData.DateFrom) -Format 'MM/dd/yyyy')
                $dateTo = (Get-Date $($EventData.DateTo) -Format 'MM/dd/yyyy')
                $dateNow = (Get-Date -Format 'MM/dd/yyyy')
                if ($dateFrom -gt $dateTo) {
                    New-UDFormValidationResult -ValidationError "The From Date $DateFrom should be in the past versus your To Date $DateTo."    
                } elseif (($dateFrom -gt $dateNow) -or ($dateTo -gt $dateNow)) {
                    New-UDFormValidationResult -ValidationError "The dates you select should be no later then today's date as no future data is available."

Can you let me know what error you are seeing in the toast?

@adam - I was able to get rid of the messages, or so I thought. Now, the messages appear instead when I click [submit].

You might want to check for $null at the beginning of your OnValidate script block.

if ($EventData.DateFrom -eq $null) 
   New-UDFormValidationResult -Valid

@adam - I did check for $null:

    } -OnValidate { 
        if ($EventData.DateFrom -eq $null) 
            New-UDFormValidationResult -Valid
        $value = (Get-UDElement -Id 'formFactor').value
        $dateNow  = Get-Date -Format 'MM/dd/yyyy'
        Switch ($value) {
            'QStore' {
                if (($EventData.txtStoreNum) -eq $null -or ($EventData.txtStoreNum) -eq '') {
                    New-UDFormValidationResult -ValidationError "Store number is required."
            } 'QRange' {

        New-UDFormValidationResult -Valid
    } -OnSubmit {

That did not seem to make a difference. It is weird. I am also getting data is null on my alerts page & the graph page, which makes sense at the moment there is no display to report. I would think if I wrapped my New-UDTable in a If ($data) block that would prevent the error, but it doesn’t seem to. I am sorry to keep hijacking this thread, please let me know if I need to create a separate thread.