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) ?