web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Conditional file attac...
Power Automate
Unanswered

Conditional file attachment to email

(2) ShareShare
ReportReport
Posted on by 26

Hi, 

 

I'm using the "Send an email (V2)" action to send an email when a form is submitted.

hzamani_0-1618904476447.png

The form includes an optional field to attach files. 

The flow works fine when there's an attachment but I can't get it to ignore attachment when there isn't any file attached.

The only way I can think of getting this done is to create multiple conditions and check if there's any attachments. If not, then using another version of "Send an email (V2)" action which doesn't have an attachment.

 

That's doable if there was only one file but my form includes multiple optional fields to upload files.

Is there any way to include an expression in the attachment section of this action like this?

 

hzamani_1-1618904714938.png

 

What I have got there at the moment is this:

 

 

 

if(equals(body('Parse_JSON_-_Proposal_Content'), null), null, first(body('Parse_JSON_-_Proposal_Content'))?['name'])

 

 

 

But I'm getting an error saying an attachment can not be null or empty.

Categories:
I have the same question (0)
  • PrasadAthalye Profile Picture
    on at

    Can you build expression like below ? If its empty I am returning string 'its empty', else actual value.

     

    if(empty( outputs('Get_response_details')?['body/rb155ddff72364222b289b17c7727a3e9']), 'its empty', outputs('Get_response_details')?['body/rb155ddff72364222b289b17c7727a3e9'])

     

  • hzamani Profile Picture
    26 on at

    Hi Prasad, thanks for the suggestion. This will also not work because if there's an attachment name, then there must be an attachment file content. I can attach a dummy file instead but this means the email will include an attachment whether or not form was submitted with an attachment.

  • PrasadAthalye Profile Picture
    on at

    Can you please clarify more what do you mean you can attach a dummy file ?

     

    I guess you are looking forward to find out if attachment exist or not? I think there are only 2 possible scenarios. Either User can attach something OR leave it empty. Are you saying there exist third use case?

  • hzamani Profile Picture
    26 on at

    I mean if I provide a dummy text for the file name, which you have in your formula ( 'its empty' ), then the Attachment Content would need an input ( a file ). 

  • PrasadAthalye Profile Picture
    on at

    Can you try to use null expression instead of 'its empty'?

     

    if(empty( outputs('Get_response_details')?['body/rb155ddff72364222b289b17c7727a3e9']), null, outputs('Get_response_details')?['body/rb155ddff72364222b289b17c7727a3e9'])
  • hzamani Profile Picture
    26 on at

    I did, as in my first post of this thread. It doesn't accept a null or empty value. 

     

  • PrasadAthalye Profile Picture
    on at

    Ok then I think you will have to use If condition block to check if following expression is empty or not...

    outputs('Get_response_details')?['body/rb155ddff72364222b289b17c7727a3e9'])

     

    then copy email action from If to else block.. Inside If, you wont add attachment and inside else you will …

     

    For the email content, you can declare a variable and use it in both actions to refactor.

  • hzamani Profile Picture
    26 on at

    Thanks. That is exactly what I'm avoiding to do. I have multiple optional file uploads in my form. So someone can attach a file to field 1 and not attach to 2 & 3 & 4, etc ,etc. Lots of combinations can happen and I'd need to create a Send email action for each. Which could be avoided if the Attachment field accepted a null / empty value.

  • AndreaMeras Profile Picture
    14 on at

    Im having the same situation. Did you manage to solve it?

  • hzamani Profile Picture
    26 on at

    Not really, I had to create multiple conditional checks and have a specific version of Send Email V2 for each scenario 🤢

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard