New-UDGriD cells colouring

HI so i was trying to colour the cells in UDGrid by passing new-udelement in the pscustom object but in turn i get these below error

Error: t.hasOwnProperty is not a function

can anyone help me out here?

Can you post your code? That will make it easier for us to understand what you’re doing.

HI thanks for your response please find the code below

New-UDDashboard -Title “Colur Testing” -Content {

New-UDGrid -Title “Service Status” -Headers @(‘Name’, ‘Status’) -Properties @(“Name”, “Status”) -Endpoint {

  Get-Service | ForEach-Object {
   
   $BgColor = 'green'
    $FontColor = 'white'
    if ($_.value.state -ne 'STARTED') {
        $BgColor = 'red'
        $FontColor = 'white'
    }

    [PSCustomObject] @{
        Name   = $_.Name
        Status = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $_.Status.ToString() }
    }
} | Out-UDGridData 

}

}

This what i have been trying can you help me out ?

Hin @manoj2994
Have a look on my example, which is working for me:

New-UDPage -url "/Home" -Endpoint {
    New-UDGrid -Headers @("Location", "Server Name", "Not Running", "Details", "Duration", "ID") `
               -Properties @("Location", "ServerName", "NotRunning", "Details", "Duration", "ID") `
               -NoPaging `
               -DefaultSortColumn "ID" `
               -Endpoint {

      $Cache:ServerObjects | ForEach-Object{
        [PSCustomObject]@{
          Location   = if ($_.Background) {
                         New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $_.Background; 'color' = $_.Foreground;} } -Content { $_.Location }
                       } else {
                         New-UDElement -Tag 'div' -Content { $_.Location }
                       }
          ServerName = $_.Server
          NotRunning = if ($_.Background) {
                         New-UDElement -Tag 'div' -Attributes  @{ style = @{ 'backgroundColor' = $_.Background; 'color' = $_.Foreground;} } -Content { if ($_.NotReachable) {"Not Reachable"} else {$_.NotRunning} }
                       } else {
                         New-UDElement -Tag 'div' -Content {if ($_.NotReachable) {"Not Reachable"} else {$_.NotRunning} }
                       }
          Details    = (New-UDLink -OpenInNewWindow -Text "Details" -Url "/detail/$($_.Location)/$($_.Server)")
          Duration   = $_.Duration
          ID         = $_.ID
        } 
      } | Out-UDGridData
    } -AutoRefresh -RefreshInterval $HomePageRefreshInterval
} # -RefreshInterval  -AutoRefresh 

Regards,
SwissResl

HI Swiss

Thanks
Have tried but still no luck,in your case you have backgroundcolor & color in variables?

Here the code snipped of my $Cache:ServerObject, which is filled with an endpoint:

if ($NotRunning -gt 0 -or $NotReachable ) {
  $BackgroundColor = "Red"
  $ForegroundColor = "White"
}
if ($NotReachable) {
  $ID = "000_$($Server.Location)"
} else {
  $ID = "$(999-$NotRunning)_$($Server.Location)"
}
[PSCustomObject]@{
    Background   = $BackgroundColor
    Foreground   = $ForegroundColor
    NotReachable = $NotReachable
    ID           = $ID
    Location     = $Server.Location
    Server       = $Server.Server
    NotRunning   = $NotRunning
    Duration     = [double]((Get-Date) - $StartTime).TotalSeconds
}

Hope this helps…

HI This is the code i have tried but in turn no luck even i tried within the endpoint could help me in spotting the error
$cache:serverobjects = Get-service | ForEach-Object {

                            if ($_.Status -eq "Stopped"){
                            
                                 $BackgroundColor = "Red"
                                 $ForegroundColor = "White"
                            
                            
                            }
                            [PSCustomObject]@{
                            
                                Background = $BackgroundColor
                                Foreground = $ForegroundColor
                                Name = $_.Name
                                Status = $_.Status
                                Machine = $_.MachineName
                                Display = $_.DisplayName
                            
                            
                            }

    }
     
     
     
     $dash =  New-UDDashboard -Title "Testing" -Content {



     New-UDGrid -Headers @("Status", "Name", "Details", "Machine") -Properties @("Status", "Name", "Details", "Machine")  -Endpoint {


      


           
           $cache:serverobjects| ForEach-Object{
            
            [PSCustomObject]@{
              Status   = if ($_.Background) {
                             New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $_.Background; 'color' = $_.Foreground}  } -Content { $_.Status }
                           } else {
                             New-UDElement -Tag 'div' -Content { $_.Status }
                           }
              Name = $_.Name
              
              Details    = $_.Display
              Machine   = $_.Machine
              
            } } | Out-UDGridData

I did a test for you without a $Cache object, which is working:

$Pages = @()
$Services = New-UDPage -Name Services -Icon gears -Content {

  New-UDCard -Title "Services" -Endpoint {

    $serverobjects = Get-service | ForEach-Object {

      if ($_.Status -eq "Stopped") {
    
        $BackgroundColor = "Red"
        $ForegroundColor = "White"
    
    
      }
      [PSCustomObject]@{
    
        Background = $BackgroundColor
        Foreground = $ForegroundColor
        Name       = $_.Name
        Status     = $_.Status
        Machine    = $_.MachineName
        Display    = $_.DisplayName
    
    
      }
    }
    New-UDGrid -Headers @("Status", "Name", "Details", "Machine") -Properties @("Status", "Name", "Details", "Machine")  -Endpoint {
      $serverobjects| ForEach-Object {
    
        [PSCustomObject]@{
          Status  = if ($_.Background) {
            New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $_.Background; 'color' = $_.Foreground}  } -Content { $_.Status }
          }
          else {
            New-UDElement -Tag 'div' -Content { $_.Status }
          }
          Name    = $_.Name
    
          Details = $_.Display
          Machine = $_.Machine
    
        } } | Out-UDGridData
    }
  }
}
$Pages += $Services

$Dashboard = New-UDDashboard -Title "UD Test Dashboard" -Pages $Pages

If you want to use $Cache:, you have to use either a New-UDEndpoint or having it in an -Endpoint-Element

Hi Swiss
Thank you so much for your help i have tried in the same machine it didn’t work but when i switch the machine and dashboard it works
what might be the possible issue ?

older machine is win 7 but dot net core is dint installed

newer machine is win 7 dot net core is installed

anything related to this?