Add data row error : object reference not set to an instance of an object

I’m having issues adding a Data Row. I’ve been browsing other forum posts on this topic and it seems like I’m making the right moves with ArrayRow and DataTable cells. Is my DataTable “Emailscrape” suppose to be already formatted in excel prior to starting the project? I’ve already initialized it in Read Range near the top level of the flowchart.

The error is System.NullReferenceException: Object reference not set to an instance of an object.


Please can you check if the Data Table is initialized and share screenshot regarding to the Data Table.

I think the DataTable is null.

1 Like

Hi @Austin_Hunter

Please Check these things.

  1. After Building DataTable, Check in.
    Prioperties whether you have assigned a .
    datatable variable.
  2. Then In Add DataRow Activity check.
    whether you have added the same.
    datatable variable.


Isn’t the data table going to be populated at the end of the flow with the Write range activity? How do I make the data table not null at the add data row activity?

Is this what you mean?

Initialized data table Emailscrape

Same data table name

Flow chart macro

Please try the following:

  1. I see the Range Chosen is from B1:F1, please remove this range selection and leave it as “”
  2. Try adding the Read Range within an Excel Application Scope and execute it.
    3 . Run in Debug mode and check what is the value of the DataTable after the Read Range activity


You can keep a condition after Get IMAP Messages as If GetImapEmailVariable.Count > 0, because you can’t except mails to be there, so if there is no mails then you will get the same error

Hope this helps you


Hi @Austin_Hunter

Check whether in that mail folder in outlook contain atleast one mail or not. If there is no mail then your variable will hold null data and there will be exception while adding into datatable.

So please add atleast one mail in that folder in outlook then run your code in uipath.


I’m getting a excel application scope error. Should I move this activity inside my For Each activity?

Please move the Read Range within the Excel Application Scope. Example screenshot attached.



Hello and Welcome to the forum. You need a condition before the add data row activity, your condition should check in all the variables you are trying to add to datable ant empty. Not var1.toString.isNullOrEmpty And Not var2.ToString.IsNullOrEmpty etc and then drag the add datarow activity inside so if one of the variables is empty this will not error out instead it will move to the else part.

I’m trying to get emails from gmail. ive enabled imap and allowed less secure apps to extract. Do you think its a problem on the gmail side?

Hi @Austin_Hunter,

Please follow below step and let me know working on gmail working or not:-

  1. For POP3 Mail Message
    follow the above procedure to configure Gmail:-

    Port: 995

2.For IMAP Mail Message

PORT: 993
Server: “
Sample workflow as follows.
EmailAutomation.xaml (8.4 KB)
If it helps Please Mark it as a solution!!! Happy Automation :partying_face:


I’m not quite sure im understanding the format. Is the follow image congruent to what you said? I’ve also tried String.IsNullOrEmpty(mail.Body.ToString) and I didn’t get a warning but didnt work

I think i did everything. configure IMAP settings, allow less secure apps, and nested the read range. I’m using my University gmail account do you think that could be the problem? (6.8 KB) (6.8 KB)

I actually got text for some the assigned variables but it seems like my data table didnt update or get exported.

I can see the DataTable left blank here

Please add the DataTable name Emailscrape in the highlighted area (In Yellow)and try again.

I’m still not getting emails to populate my data table. I think it might be because I’m using my school email. Do you see anything in the video that might cause the issue?