Cannot index into a null array

At times my dashboard running on iis will give me the cannot index to a null array error or similar error about null expression when selecting a dropdown or clicking a button to run a query

The query may sometimes run successfully even though the error appears

And sometimes after waiting 30 secs or so i can select or click the button to run query successfully without getting the errors

Im using session scope for most variables becuase the dadhboard will be used but multiple at the same time providing different variable values

Also using content insteqd of endpoint as per best practice suggestion

Any suggestion how to prevent the intermittent errors can i stop them from appearing altogether

Hi @Srichman0128 I can have this issue if I choose something and the page hasn’t fully loaded…I like to use TOASTS to show the selected data…I also deal with my components by checking the particular $session vairable is not $null before I run my queries…I think to help solve you particular problem is verfiy the version you are running of UD…then post some code examples of your dashboard…then I am sure other would chip in.

1 Like

Strangely I’m also seeing this (v2.9). I’ve been testing locally and never ran into this issue but I’ve now moved onto testing running in an Azure webapp and I’m intermittently getting this issue now. It’s an odd one though as it’s not every time and it’s not the same elements each time.

I have a modal which has a couple of text boxes and a select box. When a button is clicked it gets the values of the text boxes and the select box and does some validation to check they are not empty etc and it will toast a message if the validation doesn’t pass. Sometimes I get one, sometimes I get multiple toasts where it thinks the boxes are empty (and they aren’t). I also get the ‘cannot index into a null array’ message too when seeing this behaviour.

I appear to have stumbled across a potential answer for this in case anyone else has this issue. I was getting the value of each text box and running validation straight after. I have changed this so that once the button is pressed it gets all text box values and sets variables for each of them. Even though it should wait until the variables are set I found that some of them were null still so I then do a “Start-Sleep -Seconds 2” which allows a couple of seconds for the variables to set themselves before continuing. Then the validation can take place. I have now been able to run the form a dozen times without any of the intermittent issues appearing again.

1 Like

Update: sorry, this doesn’t fix it, the problem has come back again today. It’s completely random which values it gets. I can press the submit button and it will tell me that text box 1 is empty, then without changing any values I can press the submit button again and it will tell me that text box 3 is empty. It’s doing my head in as there’s no pattern and seemingly no reason for it!

i was able to resolve this with psDevUK’s suggestion of checking if the variable value is $null being running my queries

basically i use something like below

$session:userinput = (Get-UDElement -Id userinput -ErrorAction SilentlyContinue).attributes[“value”]

if(![string]::IsNullOrEmpty($session:userinput)){ “your scriptblock”}

or

if($session:userinput -ne $null){“your scriptblock”}

I’ve been getting round this by setting some sort of default value.

If(!$session:requireddata){$session:requireddata="something"}

@tom.obrien - I like that sleep idea though - maybe a Do/While would ensure it waited long enough?

Do{sleep or something}While(!$session:requireddata) ?