Error: For Each Row

Error_ForEach

I am getting the above error when executing my ACME Calculate Client Hash bot in the “ProcessWorkItems” sequence.

The error says: “Object reference not set to an instance of an object”.
Source: For Each Row

Can anyone help explain what I am doing wrong?

@Jonathan_Martens

I guess it did not scrape data or may be did not pass arguments properly. Try to print values using message box activity and see once.

Hey @Jonathan_Martens,

This error is encountered because of input argument in_FilteredDt which seems to be empty.

Can you please check the value of this input agument?

Your datatable variable ‘in_FilteredDT’ has not been initialized. Doublecheck in your workflow that you either have a ‘Build data table’ activity saving to your datatable variable, or have some other activity that is outputting to the ‘in_FilteredDT’ variable

EDIT: It looks like in_FilteredDT is an argument. Make sure that you are passing in the value in your argument correctly when invoking the workflow. Also, make sure you don’t have a variable with the same name, as variables take precedence over arguments. This means you could pass in a value to the argument when making your workflow, but you also have a variable with the same name that does not have a value and is null. When this happens the variable is null and you’d get the error shown in the screenshot.

It was suggested by @amarasto and @Dave that your argument could be empty.

I just wanted to add that Arguments are case-sensitive, so make sure the case is the same in both the Invoke and Workflow. Like, both should be in_FilteredDT or both should be in_FilteredDt - so you should check the case too

1 Like

Thanks everyone for your quick replies!

@Dave

You are correct that ‘in_FilteredDT’ is an argument. I do not have ‘in_FilteredDT’ set as a variable in that sequence. In the below process I am using DataScraping to build the table and output as variable ‘ExtractDataTable’ which i then assign to out_FilteredDT where I also filter for Type= “WI5”.


How do I pass the data from the variable ‘out_FilteredDT’ to the new sequence “ProcessWorkItems” where I want to use the values in the For Each loop in the photo from my first post? Do I create a new variable or new argument?

Almost forgot to mention in my assign i’m assigning the following value: ExtractDataTable.Select(“Type=‘WI5’”).CopyToDataTable

Throw in a write line activity after your assign to count the rows and make sure data is grabbed in your select statement - it would look like: out_FilteredDT.Rows.Count.ToString

To pass the data to the next sequence, you need to use the ‘Invoke Workflow File’ activity. Choose the correct workflow, then click import arguments. Assign out_FilteredDT to the in_FilteredDT argument. I would also put a write line in at the very first thing in your sequence to count the rows and make sure they match - use the same code as above in a write line activity to do that

Thanks again @Dave! I was able to resolve that error. I’m not getting a new error in my next sequence “GetClientDetailsandSearchString”. Posted below.

14:39:25.0000 => [INFO] [UiPath.Studio.Shared.Logging.OutputLogger] [23] ACME_Calc_Client_Hash execution started
14:39:32.0000 => [INFO] [UiPath.Studio.Shared.Logging.OutputLogger] [23] Opening applications…
14:40:50.0000 => [ERROR] [UiPath.Studio.Shared.Logging.OutputLogger] [13] Assign: Index was outside the bounds of the array.
14:40:50.0000 => [ERROR] [UiPath.Studio.Shared.Logging.OutputLogger] [41] Invoke Workflow File: Index was outside the bounds of the array.
14:40:50.0000 => [ERROR] [UiPath.Studio.Shared.Logging.OutputLogger] [13] Invoke RetrieveSecurityHash workflow: Index was outside the bounds of the array.
14:40:50.0000 => [ERROR] [UiPath.Studio.Shared.Logging.OutputLogger] [41] Invoke ProcessWorkItems workflow: Index was outside the bounds of the array.
14:40:50.0000 => [INFO] [UiPath.Studio.Shared.Logging.OutputLogger] [23] ACME_Calc_Client_Hash execution ended in: 00:01:25

Here is the Assign i’m using
To: Out_SearchString
Value: StrArray(2).Trim+“-”+StrArray(4).Trim+“-”+StrArray(6).Trim

What is written in the assign activity that threw the error?

An array has a fixed upper and lower bound (meaning it has a fixed number of items within it). If you try and reference an item that doesn’t exist, you’ll get that error. For example, you have an array of 3 strings arrStr = {str1, str2, str3} - if you try and reference the 5th string in the array (which doesn’t exist) you’ll get that error. It commonly occurs when you expect the array to have a number of values, but in fact has no values in it.

@Jonathan_Martens sorry you replied while I was typing! - you should make sure your array is not empty. Similar to the datatable approach a simple and quick way is to add a write line activity at a point where you expect it to have data with the code StrArray.Length.ToString

I’m using a Write Cell after to see what exactly is being captured.

Where are you getting the StrArray from? The error comes because it doesn’t have at least 7 strings in the array - note that you are getting the 3rd, 5th, and 7th string in the array since arrays have a 0-based index. If you meant to get the 2nd, 4th, and 6th string you should change it to StrArray(1).Trim+“-”+StrArray(3).Trim+“-”+StrArray(5).Trim

After using Get Text to pull the client information I am assigning the Ouput value: RetrievedStr.
Then I am assigning:
To: StrArray
Value: RetrievedStr.Split({“:”,“Client”},StringSplitOptions.RemoveEmptyEntries)
The removal of Empty Entries is why I am then doing 2,4, 6 on the next Assign:
To: Out_SearchString
Value: StrArray(2).Trim+“-”+StrArray(4).Trim+“-”+StrArray(6).Trim

I suggest checking RetrievedStr to see if it has a string… sometimes Get Text fails to get the string.

Also, check StrArray to see if has all the values it is supposed to have. you can check an array like this: String.Join("||", strArray), which will output all the values in that array to WriteLine or Message Box.

1 Like

Although the error takes me to the Assign block in my “GetClientDetailsandSearchString” sequence the errors in the output show the Index was outside the bounds of the array in two different workflows:

  • RetrieveSecurityHash

  • ProcessWorkItems

The workflow fails there because that’s where you’re trying to read the array. The source of the error is the data, which @ClaytonM points out starts in your Get Text activity, so you should first make sure the source string exists, then follow it along the line until find where it went wrong

1 Like

I put in a message box first where it grabs the “in_WIID” to navigate to the client information details. This showed the correct WIID (although it was for the very last client in the data table).

Next message box below is the RetrievedStr (looks good).
msg2