Chart empty after page reload

Hi all,

our organization just started the PoshUD journey, but we are already facing a couple of issues. This thread is about the most problematic issue.

We are running PoshUD 2.9.0 as a Windows Service.

On the dashboard we have multiple sites in place with multiple UD-Charts.
The charts are loading properly and visualize the correct data.
But as soon I start to jump through the pages or reload the page, all the chart data is gone.
And interestingly the chart data is not just gone in the same browser session, the charts are completely broken for everyone.

This is my code of one of the charts (this is actually part of the Active Directory Dashboard)

New-UDChart -Type Bar -Title "Users" -Id "ADUserChart" -Endpoint {
    $Cache:Users | Out-UDChartData -DataProperty 'Value' -LabelProperty 'Name' -BackgroundColor $Cache:ChartColorPalette 
}

The charts seem to recover at some point in time but then break the same way again.

I wasn’t able to find any errors in the debug log so far.

Thank you for your help
Seb

Hi and welcome to the UD forums!

The first thing I’d suggest trying with this is:

  1. Can you confirm that the -id on this element is definitely unique (no other elements use this).
  2. How do you set $Cache:Users? Where is the data being populated? I had a similar issue once and had coded a ‘refresh’ of the data on page load but that was causing me problems - I ended up moving it to a scheduled endpoint instead.
    If you use the admin mode console to physically inspect the contents of $Cache:Users at the time your chart is empty, you may be able to confirm if the issue is here or not.
1 Like

Thank you for your help insomniacc.

I can confirm that the -id on this element is unique.

And it also looks like that the $Cache:Users data is empty after a refresh. This at least what the Admin Terminal tells me:

PS UD:\>  $Cache:Users

Executing...

The $Cache values are already populated in a scheduled endpoint.
I load two scheduled endpoints the following way:

$Endpoints = Get-ChildItem (Join-Path $PSScriptRoot 'endpoints') | ForEach-Object {
        & $_.FullName
    }

Start-UDDashboard -Dashboard $Dashboard -Port 80 -Endpoint $Endpoints -Wait

And this is a part of the endpoint code:

New-UDEndpoint -Id "Domain1Endpoint" -Endpoint {
    try
    {
         $Cache:Loading = $true
         $Users = Get-ADUser -Filter {Name -like '*'} @Cache:ConnectionInfo -Properties EmployeeID
         $Cache:Users = @{
            Total    = ($Users | Measure-Object).Count
            Disabled = ($Users | Where-Object Enabled -eq $false | Measure-Object).Count
         }.GetEnumerator()
    }
    catch
    {
        $Cache:Error = "Failed to load AD data. $_"
    }
    finally
    {
        $Cache:Loading = $false
    }
} -Schedule (New-UDEndpointSchedule -Every 60 -Minute)

As I wrote before I’m loading multiple endpoints. They are all pulling similar data from different domains. But I made sure they are using different variables. Not sure if this might have an impact on this issue.

I’d say then it’s almost certainly not an issue with your page/elements on that page - but the way in which the endpoint is handling and pushing the data (providing you don’t have any other code on your page interacting with the same cache variable in a writable way.)

If you recycle your app pool and start fresh, is the data always loaded on first run? are you able to identify if it’s after 60mins when it goes blank - in keeping with your schedule? or does it seem sporadic/random?
I’ve never tried calling files this way into the endpoint, i dot source although i suppose there shouldnt be any difference.
Have you always had this issue with this particular chart? or is it something you have recently noticed? After any recent code changes etc? Just trying to narrow down where we need to be looking…

Also, I know the thing is wrapped in a try catch, but have you tried using -erroraction stop just in case there’s a non terminating error catching you out? or maybe put an if statement around where you’re setting the cache variable to check that the data you put through isn’t null/empty at that point.
Either way you could also put some sort of write out to a log file of your own in your endpoint with a datetime and count of the data in your cache. That way, you’d know exactly when its being set and what with, should shed some light on it.