New-UDTable and Out-TableData ConvertTo-FlatObject Error

I’m trying to implement a server-side table as described in this link: Build Server-Side tables with PowerShell Universal Dashboard

The table doesn’t render in the Dashboard and I can see there is a “ConvertTo-FlatObject” cmdlet in the function that is complaining about a null object.

Here is the code:

$Body = ’
{
“filters”: [],
“orderBy”: “undefined”,
“orderDirection”: “”,
“page”: 0,
“pageSize”: 5,
“properties”: [
“[“SamAccountName””,
““Name”]”
],
“search”: “”,
“totalCount”: 0
}

  $tabledata = $body |  ConvertFrom-Json

New-UDTable -Title “Account Data” -LoadData {
$AccountData | Out-UDTableData -Page $TableData.page -TotalCount $AccountData.Count -Properties $tabledata.properties
} -Columns @(
New-UDTableColumn -Property “SamAccountName”
New-UDTableColumn -Property “Name”
)

Here is the error in VS Code:

ConvertTo-FlatObject: C:…\UniversalDashboard\3.3.3\UniversalDashboard.MaterialUI.psm1:4322:51
Line |
4322 | … data = [Array]($Data | ConvertTo-FlatObject)
| ~~~~~~~~~~~~~~~~~~~~
| Cannot bind argument to parameter ‘InputObject’ because it is null.

But it appears to have created the table:

Name Value


showSort False
loadData UniversalDashboard.Models.Endpoint
assetId
showExport False
userPageSize 5
type mu-table
isPlugin True
size medium
userPageSizeOptions {5, 10, 20, 50}
showSelection False
padding default
data
showFilter False
textOption {exportFileName, filterSearch, exportAllJson, exportAllCsv…}
defaultSortColumn
id 6e5ea472-861c-46d2-a187-8c149c6060da
columns {f7e52421-17bb-46a9-a2d1-eeb93a4f6927, 76b4e9fb-07c8-446a-a9ca-8c9a94567d37}
showSearch False
title Account Data
showPagination False
isDense False
isStickyHeader False
onRowSelection
exportOption {XLSX, PDF, JSON, CSV}

I’m running 1.5.14… Any ideas?

Thanks

I think the convertto-flatobject-error is because $Data is not set untill -Loaddata is run. It happens when the UDTable is initated, ie before the loaddata. I’m just ignoring the error because it does no harm and I don’t think that is why nothing is rendered in you case.

What is $AccountData?

Your ‘$tabledata = …’ is outside the loaddata script block. I guess thats only in your post like that, right :slight_smile:

$AccountData is a System.Array object with a SamAccountName and Name property… I tried putting the $Body and $tabledata vars in the -LoadData block, but same result :frowning:

Do you need to do server-side processing? If not, you can just do:

New-UDTable -Data $AccountData -Columns @(
    New-UDTableColumn -Property “SamAccountName”
    New-UDTableColumn -Property “Name”
)

Yes, the table I’m trying to render takes up to two minutes to load… It has several rendered columns… I’m just testing this out with two properties for now…

Here is the updated code with some more info… In the dashboard log I see two errors:
[04-05-21 03:39:47 PM] An error occurred: Cannot bind argument to parameter ‘InputObject’ because it is null.
[04-05-21 03:39:48 PM] An error occurred: Cannot bind argument to parameter ‘Properties’ because it is an empty string.

…I wonder if it’s something wrong with the “properties” in the JSON??

$TableData looks like this:
filters : {}
orderBy : undefined
orderDirection :
page : 0
pageSize : 5
properties : {[“SamAccountName”, “Name”]}
search :
totalCount : 0

function global:GetAccountData {
$XMLPath = “C:\Scripts\UserReport.xml”
$XMLData = Import-Clixml -Path $XMLPath | Sort-Object -Property SamAccountName #| Select-Object -First 50
return $XMLData
}

New-UDTable -Title “Account Data” -LoadData {
$Body = ’
{
“filters”: [],
“orderBy”: “undefined”,
“orderDirection”: “”,
“page”: 0,
“pageSize”: 5,
“properties”: [
“[“SamAccountName””,
““Name”]”
],
“search”: “”,
“totalCount”: 0
}

$TableData = $Body | ConvertFrom-Json
$Data = GetAccountData
$Data | Out-UDTableData -Page $TableData.page -TotalCount $Data.Count -Properties $Data.properties
} -Columns @(
New-UDTableColumn -Property “SamAccountName”
New-UDTableColumn -Property “Name”
)

Ahhh ok. I was totally look at this incorrectly. You don’t need to provide $Body yourself. That will be provided automatically.

Try this

New-UDTable -Title “Account Data” -LoadData {
     $TableData = $Body | ConvertFrom-Json
     $Data = GetAccountData
     $Data | Out-UDTableData -Page $TableData.page -TotalCount $Data.Count -Properties $Data.properties
} -Columns @(
     New-UDTableColumn -Property “SamAccountName”
     New-UDTableColumn -Property “Name”
)

Same thing… I restarted the dashboard to be sure my $Body var was cleared… here is the entire trace:

[04-05-21 03:57:15 PM] An error occurred: Cannot bind argument to parameter ‘InputObject’ because it is null.

Endpoint: Assets
Session: 42ad9581-1004-46dd-a3b4-50727104c8af
File: C:\ProgramData\UniversalAutomation\Repository\psuniversal\UserAccount-Dashboard-ServerSide.ps1
Endpoint Start Line: 161
Endpoint End Line: 267
Stack Trace: at New-UDTable, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 4321
at , : line 36
at New-UDStyle, C:\Program Files\PowerShell\Modules\UniversalDashboard.Style\1.0.0\UniversalDashboard.Style.psm1: line 35
at , : line 24
at New-UDErrorBoundary, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 1692
at New-UDPaper, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 3092
at , : line 23
at , C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 75
at New-UDErrorBoundary, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 1692
at New-UDGrid, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 2159
at New-UDColumn, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 74
at , : line 22
at , C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 29
at New-UDErrorBoundary, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 1692
at New-UDGrid, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 2159
at New-UDRow, C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1: line 28
at , : line 21

[04-05-21 03:57:16 PM] An error occurred: Cannot bind argument to parameter ‘Properties’ because it is an empty string.
Endpoint: 5b87793c-98ad-4587-b820-fbc5b8747bea
Session: 42ad9581-1004-46dd-a3b4-50727104c8af
File:
Endpoint Start Line: 30
Endpoint End Line: 34
Stack Trace: at , : line 5

I also just noticed you are using $Data.Properties rather than $TableData.Properties

Updated to correct that.

New-UDTable -Title “Account Data” -LoadData {
     $TableData = $Body | ConvertFrom-Json
     $Data = GetAccountData
     $Data | Out-UDTableData -Page $TableData.page -TotalCount $Data.Count -Properties $TableData.properties
} -Columns @(
     New-UDTableColumn -Property “SamAccountName”
     New-UDTableColumn -Property “Name”
)

Can you see if that helps? I get a similar error if I do something like this:

$Columns = @(
    New-UDTableColumn -Property Dessert -Title "A Dessert"
    New-UDTableColumn -Property Calories -Title Calories 
    New-UDTableColumn -Property Fat -Title Fat 
    New-UDTableColumn -Property Carbs -Title Carbs 
    New-UDTableColumn -Property Protein -Title Protein 
)

New-UDTable -Columns $Columns -LoadData {
    $Query = $Body | ConvertFrom-Json

    <# Query will contain
        filters: []
        orderBy: undefined
        orderDirection: ""
        page: 0
        pageSize: 5
        properties: (5) ["dessert", "calories", "fat", "carbs", "protein"]
        search: ""
        totalCount: 0
    #>

    @(
        @{Dessert = 'Frozen yoghurt'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        @{Dessert = 'Ice cream sandwich'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        @{Dessert = 'Eclair'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        @{Dessert = 'Cupcake'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        @{Dessert = 'Gingerbread'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
    ) | Out-UDTableData -Page 0 -TotalCount 5 -Properties $Test
}

Yes… I noticed that too :slight_smile: I changed it to $TableData… same thing.

When running your code I see the new columns in the dashboard but no data and the same error.

What in tarnation…

I’m assuming if you correct the example I provided it works? Are you using Windows PS or PS 7?

To be honest, it seems like this is a bug. Like obviously $Data is not set so trying to pipe to ConvertTo-FlatObject should fail so I’m not sure why when I try it, it works.

data = [Array]($Data | ConvertTo-FlatObject)

Powershell 7… Yes might be a bug… To simplify things, I created a new dashboard. You can see the function works and has data…

function global:GetAccountData {
$XMLPath = “C:\Scripts\UserReport.xml”
$XMLData = Import-Clixml -Path $XMLPath | Sort-Object -Property SamAccountName
return $XMLData
}

New-UDDashboard -Title “Hello, World!” -Content {
$Data = GetAccountData
New-UDTypography -Text “`Data has ($Data.Count) objects”

New-UDTable -Title "Account Data" -LoadData {
    $Data = GetAccountData
    $TableData = $Body | ConvertFrom-Json
    $Data | Out-UDTableData -Page $TableData.page -TotalCount $Data.Count -Properties $TableData.properties
} -Columns @(
    New-UDTableColumn -Property "SamAccountName"
    New-UDTableColumn -Property "Name"
)

New-UDButton -Text "Learn more about Universal Dashboard" -OnClick {
    Invoke-UDRedirect https://docs.ironmansoftware.com
}

}

Thanks for your help!

Alright. I’ve narrowed it down. It’s a problem between PSCustomObjects and Hashtables (I think…). If I update my script like this I see the exact same error:

New-UDTable -Columns $Columns -LoadData {
    $Query = $Body | ConvertFrom-Json

    $Data = @(
        [PSCustomObject]@{Dessert = 'Frozen yoghurt'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        [PSCustomObject]@{Dessert = 'Ice cream sandwich'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        [PSCustomObject]@{Dessert = 'Eclair'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        [PSCustomObject]@{Dessert = 'Cupcake'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
        [PSCustomObject]@{Dessert = 'Gingerbread'; Calories = (Get-Random); Fat = 6.0; Carbs = 24; Protein = 4.0}
    )

    $data | Out-UDTableData -Page 0 -TotalCount 5 -Properties $Query.Properties
}

It’s happening in a really weird spot though and if I “fix” it, then no data is shown and now no error is shown. If I convert the data to a hashtable like this, it still happens. So that’s got me a bit baffled.

    $ht2 = @{}
    $Data.psobject.properties | Foreach { $ht2[$_.Name] = $_.Value }

There is certainly a bug. I’ll open a public issue to track this. I’ll get to the bottom of it. It’s just a little strange what is going on here.

1 Like

Feel free to track issue status here. I’ll make a note of this thread on the issue so that we know to update this thread when this is resolved.

1 Like