Showing results for 
Search instead for 
Did you mean: 
Level: Powered On

Condition - Attachment Contains Causes Error

We have an alerting system that sends out messages, however the status of the alert (success/failure) is contained within a .txt attachment on the email. I am attempting to create a flow that will send me a notification based on the presence of the word "failed" in the text of the attachment.


I created the following flow based on the post here: Save attachment based on content

with the exact condition of: @contains(base64ToString(items('Apply_to_each')?['ContentBytes']), 'failed')

This results in the following error:


InvalidTemplate. Unable to process template language expressions for action 'Condition at line '1' and column '2394: 'The template language function baseo4ToString expects its parameter to be a string. The provided value is of type 'Null'. Please see for usage details.'.


Removing the conversion from base64tostring only causes the error to change to the following:


InvalidTemplate. Unable to process template language expressions for action 'Condition at line '1' and column '2394' : 'The template language function 'contains' expects its first argument 'collection' to be a dictionary (object), an array or a string. The provided value is of type 'Null'.'.


Based on this, I believe I am incorrectly requesting the attachment contents from Flow. The attachment I am testing with is a basic ASCII text file with no special characters or affectations created on a Windows PC using VSCode. I do not believe there is anything unique about the text file I am using to cause this behavior.


What error am I making in the way I am fetching the content of the email attachment?

Community Support Team
Community Support Team

Re: Condition - Attachment Contains Causes Error

Hi @AaronDubin,


Could you please share a screenshot of your flow's configuration?


I have made a test on my side and don't have the issue that you mentioned. My flow's configuration as below:

  • Add a "When a new email arrives" trigger, Has Attachment field and Include Attachments field are both set to Yes.
  • Add a "Apply to each" action, input parameter set to Attachments dynamic content of the trigger.
  • Within "Apply to each", add a Condition, click "Edit in advanced mode", type the following formula:
@contains(base64ToString(items('Apply_to_each')?['ContentBytes']), 'failed')

     Within "If/yes" branch of Condition, add a "Send me an email notification" action.


Image reference:25.JPG

The flow works successfully as below:26.JPG



Please check if you have set Has Attachment field and Include Attachments field to Yes within the "When a new email arrives" trigger on your side.


Best regards,


Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources


Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.


Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020


Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!


Microsoft Learn

Learn how to build the business apps that you need


Power Platform World Tour

Find out where you can attend!


Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 62 members 4,889 guests
Please welcome our newest community members: