Wait for Doc Validation and Resume - Object Reference not set to instance of an object

Hi Everyone,

I know that the object reference error is when a variable value is not initialized, however the issue is kind of weird. I am using a For Each loop to access each PDF in a shared folder and then using document understanding to extract some information and upload it to Action Center. Now when I do this without using Wait for Document Validation and Resume and just add to collection after Create Document Validation Action - the for each loop work. However when I add Wait for Validation and Resume Activity, the For Each only loops through one file and then shows error - object reference not set to an instance of the object.
Please assist

Use Debug to see exactly which activity is throwing the error.

1 Like

I did and the Debug shows error in For each loop however the same for each loop works when I try without Wait for Validation. Also the For Each loop works when the folder has just one pdf file

Is the error happening when there are NO files? Because you can get that error when your Directory.GetFiles returns nothing.

1 Like

When there are no files, I get the error right at the start of the loop, however there are 4 files right now and the For Each loop runs through the first file - adds the result to the excel sheet, however when it attempts the second file - it throws an error

Do what files are in the folder change as the loop is running?

Yes I do get the output for 1st file and also when I do a write line after the activity I get the count of items in the folder

That didn’t answer my question.

Are files added to or removed from the folder by some outside process or person, while your loop is running?

no they are not. I have 3 file in there now and they are the same since morning

Run it in Debug mode and when it gets to the error it will stop. Before you click Stop, show me the error from the Output pane, and which activity it stopped on. Screenshots are best, you can literally just paste them into this reply box.

Hello,
Even I am facing the same issue. It breaks at the beginning of for each loop and am getting the below error

Hello,
I was facing similar issue while processing documents in a For each loop, when some of the documents in the list were addressed using an Action Center task. After a validation task from action center was addressed and the process was resumed, it failed when the loop was re-iterated for the next document with a reason "Object reference not set … ". Below is the reason according to me and the resolution that I have used.

Reason :- when the task is created in action center and the activity for “Wait for document validation” is triggered, the process gets suspended and retriggers once the task is addressed in Action Center and Resume is clicked in studio. At this time, the variable in for each has blank value (possibly since the process was suspended) and hence the error.

Solution: Assuming the documents are read from a folder using “Directory.GetFiles” method and each document is iterated in “For Each”, below are the resolution steps I followed

  1. All the successfully processed documents should be moved to another folder in each step
  2. Use a Do while loop and add the entire “for each” in it
  3. Below the for each, add an assign activity and read the folder again to know whether there are files left in it (Directory.GetFiles)
  4. Assign the value in step 3 to the variable which is used for iterating the “for each” loop
  5. Give a condition in the do while to check whether the string array (variable in for each) after reading the file is not empty

step 4 will help that variable to get the value back and step 5 will help to run further only if there are files left for processing

That means that the variable has not been initialized (if complex datatype ie datatable, dictionary, etc) or was never assigned a value (string, int, etc)

In my flow, it was initialized in the very beginning, before the for loop runs. However, when the validation task in action center is addressed and the process is resumed, the variable in for loop does not seem to be having any value (possibly since the process is suspended till the task in AC is completed). this could perhaps be a glitch, but the way I have suggested, could be a workaround to it.