Index was outside the bounds of the array

Good afternoon,

I’m running into an intermittent error on my Dashboard.

A card is no longer displayed and error message “Index was outside the bounds of the array” is displayed.

New-UDColumn -size 3 -Id “TITLE” -Endpoint {

        if (($Cache:ServerNamebackground -eq $Cache:BGPass) -and ($Cache:ServerNameping -eq $Cache:BGPass)){
            $Cache:ServerNamefinal = $Cache:BGpass
            New-UDCard -Id "TITLECard" -Title "TITLE" -Size small -BackgroundColor $Cache:ServerNamefinal -Endpoint{
            }
        }
        else {
            $Cache:ServerNamefinal = $Cache:BGfail
            New-UDCard -Id "TITLECard" -Title "TITLE" -Size small -BackgroundColor $Cache:ServerNamefinal -Endpoint{
                New-UDParagraph -Text $Cache:ServerNamefailedService
                New-UDParagraph -Text $Cache:ServerNamefailedping
                New-UDParagraph -Text $Cache:ServerNameWMI
            }
        }
    } -AutoRefresh -RefreshInterval 10

I am using multiple scheduled endpoints to populate multiple cached variables and then building a card based on the variables.

This error affects single cards at a time. Has anyone seen this before?

Hi @K_Summers

Weird!
What does the UD log show?

Could you try to wrap everything in the cards inside a new-udelement -tag span?
Sounds like an issue on the way the “array” is passed from the endpoint of the second card to the clientside.

I respect @BoSen29 with his words…but just having a quick butchers at your code, I get the feeling this could be a scoping issue…
$Cache:ServerNamefinal = $Cache:BGpass is declared outside of an endpoint, and your then declaring an endpoint in your card…so thinking is it not registering it has been changed…also no digs at your code cause if it works great, but I sometimes have issues with endpoints, so reading from the best practises is if you set less enpoints the better…So have you tried putting all this in a UDColumn with an ID and an endpoint then everything inside that can use the CONTENT script block…less endpoints less scoping issues…as mentioned I seem to get much more responsive dashboard setting the endpoint on the New-UDColumn then everything in that in a content block, and either sync the column or auto refresh it depending on your need…I would look at syncing this data once the if statement is done…thats my 2pence worth…I hope it helps…Peace

Thank you for the link to “Content vs Endpoint” as it really helped cement the differences for me. It’s honestly been a grey area since my first dive into UD.

I have modified the code so there is only a single Column level endpoint with the content inside.

New-UDColumn -size 3 -Id “TITLE” -Endpoint {

    if (($Cache:ServerNamebackground -eq $Cache:BGPass) -and ($Cache:ServerNameping -eq $Cache:BGPass)){
        $Cache:ServerNamefinal = $Cache:BGpass
        New-UDCard -Id "TITLECard" -Title "TITLE" -Size small -BackgroundColor $Cache:ServerNamefinal -Content {
        }
    }
    else {
        $Cache:ServerNamefinal = $Cache:BGfail
        New-UDCard -Id "TITLECard" -Title "TITLE" -Size small -BackgroundColor $Cache:ServerNamefinal -Content {
            New-UDParagraph -Text $Cache:ServerNamefailedService
            New-UDParagraph -Text $Cache:ServerNamefailedping
            New-UDParagraph -Text $Cache:ServerNameWMI
        }
    }
} -AutoRefresh -RefreshInterval 10

However, the issue has returned today. Digging deeper, it seems to resolve itself after one of my scheduled endpoints is run. While I agree that less endpoints is better, my need requires more than a few.

Endpoint for testing Ping status – Often
Endpoint for testing running services – Less often
Various endpoints for testing other specs on remote servers-- Frequency depends on data

Is there a certain level of UD-Logging suggested? Or possibly a certain thing to look for in the logs? With this being intermittent, my log files become huge before an error occurs.

Thank you again