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
File:
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 += $filter.id + " 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 "https://sccm-gateway.uaa.alaska.edu:5000/CheckOU/$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'
#$TestSQL
Sync-UDElement -Id 'HardwareDevices'
Hide-UDModal
} 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 {
Hide-UDModal
}
}
}
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)"
Hide-UDModal
}
New-UDButton -Text "NO" -Icon (New-UDIcon -Icon times_circle -Color 'red' -Size 'lg') -OnClick {
Hide-UDModal
}
}
}
}
) -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)"
$table.rows.add($row)
} else {
$table.Select("HardwareID = '" + $($Item.SerialNumber) + "'").Delete()
}
}
}
Any help would be greatly appreciated.
Thank you.
Product: PowerShell Universal
Version: 2.1.0