How to proceed when Match activity fails to return any result

Hi there,

I’m currently working on transposing data from multiple PDF invoices to an Excel table.

“Match” activity with Regex expressions are used to extract different fields on the PDF invoice to the Excel table.

Had problem with one of the invoice fields - “PO Number”, as some invoices’ “PO Number” fields are empty, and my program crashed when it ran into them.

Below is the error message:

Source: Write PO Id (this is the Excel application scope function to write PO Id into Excel table)

Message: Object reference not set to an instance of an object.

Exception Type: System.NullReferenceException

Am thinking of using the IF function (to check if the PO number exists before proceeding) but unsure how to do it. If there are other methods to circumvent this problem, please feel free to share with me. Thanks!

Hi,

Object reference not set to an instance of an object, we get this error when the value in a variable is empty, and as you said sometimes you are not getting PO Number, so after extracting the PO number first you can check whether PO number is empty or not

Use and IF condition and write the below expression
string.isNullorEmpty(PO Number) and PO Number.lengh>1

Hi thanks for the reply.

Tried using the suggested method but Uipath does not allow (Exclamation mark). I guess this is because the variable PO Number is of the type “IEnumerable” and not the typical String type. As far as I know, it needs to be of this variable type in order to work in Match activity.

I will need another solution to work around this.

But while using in If condition, convert the ienumerable type to string type, try using .tostring method for that variable

Thanks for the suggestion and I tried using .tostring to convert the IEnumerable variable.

However, regardless of whether the invoices have PO Number or not, the output is always the same as below:
“System.Linq.Enumerable+d__97`1[System.Text.RegularExpressions.Match]”

As such I was unable to use this as a condition in the IF function.

Hi,

Are you using Matches activity or Match Method in Assign statement.

Hi I’m using Match Activity. Please refer to screenshot below:

Hi,

You are using matches activity, so the output of matches activity is collection of ienumerable matches.

Can you use match method in assign statement,first import system.text.regularexpressions

Regex.match(input string, pattern) and store this value in a string variable, now you will be able to use in if condition

Hi there,

I have imported the system.text.regularexpressions.

By “match method in assign statement”, are you referring to assigning a standard variable (string) to the ienumerable variable so it can be used in IF activity?

Will you also be able to teach me on how and where should I use the regex.match syntax? Thanks.

Hi @jerryl27

You can also use Try Catch Method to tackle this.

Keep your Matches in Try Section.
And Catch an Exception Namely, ‘NullException’

This way you will be able to pass through this in NO-PO case.

Hi,

In assign statement in left field, take a string variable and in the right field use this expression Regex.match(input string, pattern)

Thanks to all for the help. It was found that by setting the condition of “poid.count = 0” under IF activity has helped to resolve this issue of invoices with no PO number.

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.