How to use Query of office 365

Hello UiPath Family,

I am replacing outlook activity with microsoft 365 office, while configuration facing issue of filtering mail of Get mail activity, in this activity outlook filter property expression adding is “[ReceivedTime] >='”+DateTime.Now.AddDays(-2).ToString(“MM/dd/yyyy 00:00AM”)+“'” Exactly the same as above but in office 365 MS inside query property showing error : Get Mail: Code: BadRequest
Message: Invalid filter clause: An identifier was expected at position 68.

Can you please help me to add datetime -2 days logic in office 365

Thanks you in advance.

In the Microsoft 365 Office (Outlook) activities for UiPath, you need to use the OData filter syntax to filter emails. Here’s how you can modify your filter to get emails received within the last 2 days:

You can use the DateTime object in C# to calculate the date two days ago, and then format it according to the OData filter syntax. Here’s an example of how to do this:

"ReceivedDateTime ge " + DateTime.Now.AddDays(-2).ToString("yyyy-MM-ddTHH:mm:ssZ")

In this filter:

  • ReceivedDateTime ge means “greater than or equal to” the specified date.
  • DateTime.Now.AddDays(-2) gets the date and time exactly 2 days ago.
  • ToString("yyyy-MM-ddTHH:mm:ssZ") formats the date in the “yyyy-MM-ddTHH:mm:ssZ” format, which is the required format for the OData filter.

So, your final filter expression would look like this:

"ReceivedDateTime ge " + DateTime.Now.AddDays(-2).ToString("yyyy-MM-ddTHH:mm:ssZ")

This will filter emails received within the last 2 days in Microsoft 365 Office (Outlook) activities for UiPath.

Hi Chaitan , Thank-you so much for quick reply , just one doubt above expression will match time include “00:00AM” as well?

Not required you can ignore

Great , Thank-you chethan

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