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

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Change Email Body base...
Power Apps
Unanswered

Change Email Body based on "if-then" statements?

(0) ShareShare
ReportReport
Posted on by 8

I am trying to find a "cleaner" solution to my current implementation.

 

I have built a MS Form that has a few different sections and about 50 questions total. Since this form is using branching, not all questions will ever be answered by a single user in a single session. At the completion of the form, the answers are emailed out to me.

 

The issue is that the email body would have all of the questions, even those without answers. I have managed to address this by using switches (controls), and based on what "branch" they go down, the email only documents and shows the answers for the specific questions in that particular branch. Unfortunately, this means that I could have MANY different "send an email" action and if I change anything I then have to modify each of those actions.

 

I see that when editing the body of the email, I can reference "if(expression, valueifTrue, valueifFalse)" in the expression functions.

Could I build a single "send an email" action and in the body of the email use expressions to build the message? For instance I could use something like (very simplified):

-----email body------

 

 

if "answer1 not equal to null"; then
echo "Question #1"
echo "$answer1"
fi
if "answer2 not equal to null"; then
echo "Question #2"
echo "$answer2"
fi

 

 

---- end of email body-------

 

This way I could only provide the Question and Answer of those that were populated in the email body. Minimizing the number of "Send an email" actions I would need and probably making my coding more efficient overall.

 

Thanks in advance,

 

pdxwarrior

Categories:
I have the same question (0)
  • pdxwarrior Profile Picture
    8 on at
    Re: Change Email Body based on "if-then" statements?

    Allow to me to elaborate with a better example.

    I have the following series of questions....

    "Do you have a pet?"
    Yes (Go to --Category Section--)
    No (Go to --Final Question--)
    
    --Category Section--
    "What kind of pet do you have?"
    Dog (Go to Dog section)
    Cat (Go to Cat section)
    Other (Go to Other section)
    
    --Dog Section--
    "What is your dogs name?"
    (Text Box) (Goes to --Final Question--)
    
    --Cat Section--
    "What is your cats name?"
    (Text Box) (Goes to --Final Question--)
    
    --Other Section--
    "What is kind of pet do you have?"
    (Text Box) (Goes to next question)
    
    "What is your pets name?"
    (Text Box) (Goes to --Final Question--)
    
    --Final Question--
    "What is your name?"
    (Text Box)
    
    --End of Survey--


    Now for the Email body.... I am hoping to have it dynamic with "If" statements..

    ---Email Body---

    You have received a survey....
    
    (This question has to have an answer, so populate:)
    Do you have a pet?
    (Answer)
    
    (Category might not be filled in if they don't have a bed, so don't display if empty)
    if "do you have a pet" == "Yes"; then
    What kind of pet do you have?
    (Answer)
    fi
    
    (User selected dog, so display dog questions/answers)
    if "What kind of pet do you have" == "Dog"; then
    What is your dogs name?
    (Answer)
    
    fi
    
    (User selected cat, so display cat questions/answers)
    if "What kind of pet do you have" == "Cat"; then
    What is your cats name?
    (Answer)
    
    fi
    
    (Did person enter their name?)
    if "What is your name" != null"; then
    What is your name?
    (Answer)
    fi

    could also work with "if-elsif" type statements if supported..

  • kylzbaba Profile Picture
    182 on at
    Re: Change Email Body based on "if-then" statements?

    How about patching this to a data source and then you can get fetch the date using the trigger when an item is created and then on the flow you initialize an array variable. Using get items, set the filter value to ID eq when_an_item_is_created ID (dynamic content). This is important because we want to trigger a loop. So on the for each loop, for each field we send it to an condition to check if it is null. It if isn't qppend to the array we initialized

     

    It will look like this

    {

    "Question":"Answer"

    }

     

    This will create multiple rows of items that where bot blank and you can then create a html table of the output qnd send it your mail. 

     

    You can delete the item from the list after if you do not want to leave it there.

     

  • pdxwarrior Profile Picture
    8 on at
    Re: Change Email Body based on "if-then" statements?

    I'm new to using power apps and this is a learning thing for me too.  I'm not sure that I know how to tie this into an external data source and then pull from that.  Hmm.  Is there a good tutorial or reference you could point me to?
    Also, would this then be writing an external file, pulling from that file and then deleting after processing?  How would that work if multiple people were completing the survey form at the same time?

    Apologies for the newbie questions!

  • kylzbaba Profile Picture
    182 on at
    Re: Change Email Body based on "if-then" statements?

    This will guide on how to work with getting responses from forms. 

    https://www.google.com/amp/s/normyoung.ca/2020/09/11/get-responses-from-forms-to-microsoft-lists-using-power-automate/amp/

     

    You can always reach out if you need more information.

    And each response is handled individually and separately so don't worry about any clash even if a 100 people fill it at once.

     

     

    Please accept this as a solution if it answers your question.

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 836 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 231 Super User 2025 Season 2

Last 30 days Overall leaderboard