Invoke Power Shell: Cannot index into a null array

I’ve been stuck on this issue for awhile and would definitely appreciate some assistance!

I am using Powershell to pull a customer name from an email subject using regex; then wanting to pull the result back into UiPath for reporting later on.
UiPath is reading and storing the email subject into a variable that I am then trying to pass into Powershell as an argument.
PScode:
$pattern = "Paycheck Protection Program documents for (.+), Received "
$args[0] -match $pattern | Out-Null
$Matches[1]

I have ensured that UiPath is successfully pulling the EmailSubject variable from locals while debugging.

But am still getting “Cannot index into a null array” error every time it hits the Invoke Power Shell activity.

Example subject (EmailSubject): From Payroll Protection Admin via DocuSign, Subject Paycheck Protection Program documents for Scarlett Segura , Received 5:49 PM, Size 50 KB, Flag Status Unflagged,
Example customer name result(Regex): Scarlett Segura

Is the error specifying the line number and character where the error occurs?

You can do it with upath as well instead of powershell. All you want to get sender name?
You can use below workflow. You can set the values of “get outlook mail activity” into config file to make it more dynamic and configurable.
Note: Add email subject into filter of "get outlook mail activity.REGNU_File_Download.xaml (6.1 KB) "

Unfortunately it is not the sender name I need. It is the customer name within the subject line.

No, I only get the null array error from UiPath,
This is the full exception:
RemoteException wrapping System.Management.Automation.RuntimeException: Cannot index into a null array.
at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance,
ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)

Hello @ScarlettRogue,
I changed your PowerShell code a little bit, I replace $arg[0] with a Param section:

#-Begin-----------------------------------------------------------------

Param(
  [String]$EmailSubject
)

$pattern = "Paycheck Protection Program documents for (.+), Received "
$EmailSubject -match $pattern | Out-Null
$Matches[1]

#-End-------------------------------------------------------------------

$arg[0] don’t work in this context.

Here my workflow:

In the properties of the Invoke PowerShell activity you must set the flag IsScript and the TypeArgument to String:

image

And in the Parameters I set this:

And it delivers the result you expected:

image

Best regards
Stefan

1 Like

#-Begin-----------------------------------------------------------------

Param(
[String]$EmailSubject
)

$pattern = "Paycheck Protection Program documents for (.+), Received "
$EmailSubject -match $pattern | Out-Null
$Matches[1]

#-End-------------------------------------------------------------------

That worked! I was unaware that it would not accept $args
Thank you so much!

1 Like

Just to explain what I ended up with.

I made the mentioned PS code changes and parameter change in UiPath

However, I am just calling the code from it’s saved location rather than with the additional Read Text File activity. I am also leaving the IsScript unchecked and everything is working as desired.

1 Like

Thank you for sharing your experience.

1 Like

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