Lesson 11 practice 1

Hi Fellows,

I’m trying to crack the practice 1 with the walkthrough provided by academy.

Since I don’t have Outlook account, so the Outlook activity is changed to IMAP activity throughout.

After running the workflow, I’ve received 1 exception related to “if” clause.

Here is the full exception:
"Session 11 has thrown an exception

Source: If

Message: Object reference not set to an instance of an object. This error usually occurs when using a variable with no set value (not initialized).

Exception Type: NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)"

So, I debugged a bit myself.
What I can confirm are the following:

  1. The “Get IMAP mail” activity works fine, since I can print out the mail 1 by 1
  2. The “Read range” activity works fine, as above

My suspicion is that the variable “mail”, which was a temporary variable set in the “For each” activity, doesn’t work inside the “For each row” activity.
(The “For each row” activity is wrapped within the “For each” activity)

Here is the screenshot of the workflow:

Anyone has encountered a similar issue?

This should work fine. Have you set the variable type in the For Each properties to MailMessage?

RD

NO I didn’t do.

Hi, Yes, I did set the “TypeArgument” of “For Each” to be “System.Net.Mail.MailMessage”.

What are you doing inside the For Each?

Hi, RD, Thanks for the help!

I follow exactly what the practice workflow describes. Here is the whole workflow from academy (some screenshots are missing):


Practical Exercise - Walkthrough

Depending on what mail server / client you are using, the properties due to be set might be different, however the logic and activities would be similar. When using in this walkthrough Get Outlook Mail Mail Messages, it refers mostly to Get XXX Mail Messages, which XXX could be POP3, IMAP, Exchange, Outlook.

We will start by dragging an activity Get Outlook Mail Messages, we configure which account to read from (if we need one which is not the default account in Outlook), the folder to read from and we create a variable in which the emails will be output. Let’s call this variable, emails

We will also use a Read Range activity to read the “rules” from the email rules.xlsx file, provided as input. We will Output the result into a DataTable which we will call mailRules

Notice that the emails variable, created by us in the output property of Get Outlook Mail Message, is of type List

As we are trying to apply the rules to each email, we will create an iteration on this emails list by using a For each activity. Considering the list we are iterating consists of MailMessage objects, each item from the iteration will be of type MailMessage and we need to specify this explicitly.

We click on the For each activity and in the property called TypeArgument, we choose from the options in the list, the value System.Net.MailMessage.

If this option is not on the list, please click on Browse for Types and search for the System.Net.Mail.MailMessage in the appearing dialog window.

Now we need to iterate on each of the rules and see if the current mail we are analysing meets any of the criteria. This time we have a DataTable object so we will iterate it much more comfortable with a For each row activity. The only thing you need to specify is the object to iterate on, which in our case is mailRules

We now need to check if the rules on the subject apply. As we have access to the current email in the item (we renamed it to mail) variable created automatically and this variable is of type

MailMessage, we can access all specific mail properties. We have to see if the Sender.Address property contains the column “Sender” from the current rule being checked

If that is true, we use a Move Outlook Mail Message and we move the current mail to the folder that is specified in the current row on column “Folder”

We also need to add a break to this sequence, in order not to verify the other rules anymore, if one was already applied and the mail was moved to another folder.


And in my first message, the workflow picture includes all activities in the “for each” loop.

Sorry, didn’t see the full picture :frowning:

What do you get from the mail.subject.tostring log message? Or is that where the error message is being thrown from?

I use the log message to test if the “read range” and “for each” activities perform correctly.
The error prompts after the workflow enters “if” statement.

If I replace the if condition to a simple math, for example “1+1=2”, without calling the variable “mail”. Then the “if” works, and the error will prompt after entering “Move IMAP mail message” activity. Thus I’m certain that the variable “mail” created by “for each” loop fails in the “if” statement.

Hi,
Could you please attach workflow.

Hi ddpadil,

Thanks for the help!

Here is the workflow.
Due to security issues, I have removed my Email account information from Get IMAP and Move IMAP activities.

Apart from that, everything is as what I had in the screenshot.

Also here is the Sample Excel file that comes with the practice.
Please put them in the same folder. (I didn’t specify a different path in the read range activity for Excel file)E-mail Rules.xlsx (8.3 KB)
Session 11 practice 1.xaml (14.0 KB)

Hi,
Made this change in if condition .It’s working now.
mail.From.Address.Contains(row(“Sender”).ToString)
Here we go.
Session 11 practice 1.xaml (15.3 KB)

Thanks a lot!
It works flawless!

I’ve check the difference between “sender” and “from” at here:

If I understood correctly, the “Sender” of the mail corresponds to the “From” method in MailMessages this class.

Hi team,
I am having trouble walking through the same exercise setting if condition.

I copied & pasted what @ddpadil had previously provided here but it didn’t work for me and got an error :

Honestly, I am not so familiar with VB but I kind of figured out that it could be “MailMessage” insead of “mail” so I set it as:
MailMessage.From.Contains(row(“Sender”).ToString)

Still I’ve got complier error shown in the screenshot.

What am I doing wrong? Please advise me.

Thank you.

Hi,
Small mistake ::slightly_smiling_face:
Looks like you have mentioned MailMessage which the object of system.net.malimessage in the if condition.
You just has to pass the For each item of the mail variable in the if condition.

ex:mail

mailIf

1 Like

Hi team,
I am also facing the issue inspite of following the steps of walkthrough.
Whenever i run my workflow, it states that the “Folder mentioned in the Get Outlook Mail Message is not found.”
I am also not able to understand that if it necessary to have an Outlook account.
I tried to implement what @ddpadil had provided yet the error message is same.

However, I am attaching the screenshot.
Highly appreciated , if anyone can help.

Does mail composed of multiple account/shared account.
In that case please mention in Account property.

Hi,
I am also getting same exception. Not sure what is the issue. I am able to read subject though. Any help appreciated. Thanks.

hi i am new to this i am getting the same error let me show you

flowchart has thrown an exception

Source: Get row item

Message: Object reference not set to an instance of an object. This error usually occurs when using a variable with no set value (not initialized).

Exception Type: NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)