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 Apps / If Statement in body o...
Power Apps
Unanswered

If Statement in body of email

(0) ShareShare
ReportReport
Posted on by

Hi Experts! 

 

I have an app that is logging the assigned hardware to staff and when the IT department issues out some equipment, it emails people to say what has been issued. I have text input boxes for things like Make, Model, Serial Number, Computer Name and in the body of the email it sends out, I only want it to show the information that has been entered and if nothing has been entered in the text input then it doesn't display it in the body of the email.

 

Below is my current code, on the line under Employee Name, i'm wanting to create some if statements, for example, if textinput1 is blank then don't display anything but if textinput1 is not blank then display the line in the body of the email like <b>Laptop Make:</b>"&Form3.LastSubmit.LaptopMake&"<br>

 

SubmitForm(Form3);

Office365Outlook.SendEmailV2(NewEmployeeGlobalAddressList.Text , "Equipment Assigned For Employee "& Form3.LastSubmit.Title&"" , "Hi,<br><br>

Equipment has now been assigned for an employee<br><br>

<b>Originally Requested By:</b>"&Form3.LastSubmit.'Created By'.DisplayName&"<br>
<b>Original Request Date:</b>"&Form3.LastSubmit.Created&"<br>
<b>Employee Name:</b>"&Form3.LastSubmit.Title&"<br>

Regards<br><br>"
);

Navigate(Success)

 

Please help, Thanks in Advance!

 

Categories:
I have the same question (0)
  • KRider Profile Picture
    577 Super User 2024 Season 1 on at

    You can definitely use If's in email bodies.

     

    Office365Outlook.SendEmailV2(NewEmployeeGlobalAddressList.Text , "Equipment Assigned For Employee "& Form3.LastSubmit.Title&"" , "Hi,<br><br>
    
    Equipment has now been assigned for an employee<br><br>"&
    If(
    IsBlank(Form3.LastSubmit.'Created By'.DisplayName),
    "",
    "<b>Originally Requested By:</b>"&Form3.LastSubmit.'Created By'.DisplayName&"<br>"
    )&"
    <b>Original Request Date:</b>"&Form3.LastSubmit.Created&"<br>
    <b>Employee Name:</b>"&Form3.LastSubmit.Title&"<br>
    
    Regards<br><br>"
    );

     I only did the first one as an example. Happy coding! 😄 

     

     

  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    hey @Dave-ITMan 

     

    can u try this:

    // Start by creating a base for the email content
    Set(varEmailBody, "Hi,<br><br>" &
     "Equipment has now been assigned for an employee<br><br>" &
     "<b>Originally Requested By:</b> " & Form3.LastSubmit.'Created By'.DisplayName & "<br>" &
     "<b>Original Request Date:</b> " & Text(Form3.LastSubmit.Created, DateTimeFormat.ShortDate) & "<br>" &
     "<b>Employee Name:</b> " & Form3.LastSubmit.Title & "<br>");
    
    // Conditionally add information about the laptop make if it's not blank
    If(!IsBlank(Form3.LastSubmit.LaptopMake), 
     Set(varEmailBody, varEmailBody & "<b>Laptop Make:</b> " & Form3.LastSubmit.LaptopMake & "<br>")
    );
    
    // Add other conditional fields similarly
    If(!IsBlank(Form3.LastSubmit.LaptopModel), 
     Set(varEmailBody, varEmailBody & "<b>Laptop Model:</b> " & Form3.LastSubmit.LaptopModel & "<br>")
    );
    
    If(!IsBlank(Form3.LastSubmit.SerialNumber), 
     Set(varEmailBody, varEmailBody & "<b>Serial Number:</b> " & Form3.LastSubmit.SerialNumber & "<br>")
    );
    
    // Finish off the email
    Set(varEmailBody, varEmailBody & "Regards,<br><br>");
    
    // Now, send the email using the variable 'varEmailBody'
    SubmitForm(Form3);
    Office365Outlook.SendEmailV2(NewEmployeeGlobalAddressList.Text, 
     "Equipment Assigned For Employee " & Form3.LastSubmit.Title, 
     varEmailBody);
    
    Navigate(Success);
    

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • WarrenBelz Profile Picture
    153,040 Most Valuable Professional on at

    Hi @Dave-ITMan ,

    Putting it as the last line ion the email

    SubmitForm(Form3);
    Office365Outlook.SendEmailV2(
     NewEmployeeGlobalAddressList.Text , 
     "Equipment Assigned For Employee " & Form3.LastSubmit.Title & "" , 
     "Hi,<br><br>
     Equipment has now been assigned for an employee<br><br>
     <b>Originally Requested By:</b>" & Form3.LastSubmit.'Created By'.DisplayName& "<br>
     <b>Original Request Date:</b>" & Form3.LastSubmit.Created & "<br>
     <b>Employee Name:</b>" & Form3.LastSubmit.Title & "<br>" &
     If(
     Len(TextInput1.Text) > 0,
     "<b>Laptop Make:</b>" & Form3.LastSubmit.LaptopMake & "<br>"
     ) & 
     "Regards<br><br>"
    );
    Navigate(Success)

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Dave-ITMan Profile Picture
    on at

    Hi @WarrenBelz ,

     

    Thank you for the options, i've gone for your second option to begin with as it looks like I can understand that much easier 🙂 , i've just done as you've said but I had to remove the quotes at the end of <br> as it was erroring on the button.

     

    My code so far to test it is

    SubmitForm(Form3);
    
    Office365Outlook.SendEmailV2(NewEmployeeGlobalAddressList.Text , "Equipment Assigned For Employee "& Form3.LastSubmit.Title&"" , "Hi,<br><br>
    
    Equipment has now been assigned for an employee<br><br>
    
    <b>Originally Requested By:</b>"&Form3.LastSubmit.'Created By'.DisplayName&"<br>
    <b>Original Request Date:</b>"&Form3.LastSubmit.Created&"<br>
    <b>Employee Name:</b>"&Form3.LastSubmit.Title&"<br> &
    If(
    Len(LaptopMakeTxt.Text) > 0,
    <b>Laptop Make: </b>"&Form3.LastSubmit.LaptopMake&"<br>
    ) & 
    If(
    Len(LaptopModelTxt.Text) > 0,
    <b>Laptop Model: </b>"&Form3.LastSubmit.LaptopModel&"<br>
    ) & 
    If(
    Len(DesktopMakeTxt.Text) > 0,
    <b>Desktop Make: </b>"&Form3.LastSubmit.DesktopMake&"<br>
    ) & 
    
    Regards<br><br>"
    );
    
    Navigate(Success)

     

    When I click the submit button, the body of the email is coming through like the below?

    Hi,

    Equipment has now been assigned for an employee

    Originally Requested By:Flow
    Original Request Date:18/04/2024 15:02
    Employee Name:Staff 1
    If( Len(LaptopMakeTxt.Text) > 0, Laptop Make:
    ) & If( Len(LaptopModelTxt.Text) > 0, Laptop Model:
    ) & If( Len(DesktopMakeTxt.Text) > 0, Desktop Make:
    ) & Regards

     

    Thanks 

  • Verified answer
    WarrenBelz Profile Picture
    153,040 Most Valuable Professional on at

    Hi @Dave-ITMan ,

    You need all the HTML "chunks" to be enclosed on quotes '' and the rest not. Apart from the start of the body (3 lines all in one set of quotes), I have made each line either HTML quote enclosed or code which is not enclosed.

    Office365Outlook.SendEmailV2(
     NewEmployeeGlobalAddressList.Text, 
     "Equipment Assigned For Employee " & Form3.LastSubmit.Title, 
     "Hi,<br><br>
     Equipment has now been assigned for an employee<br><br>
     <b>Originally Requested By:</b>" & 
     Form3.LastSubmit.'Created By'.DisplayName & 
     "<br><b>Original Request Date:</b>" & 
     Form3.LastSubmit.Created & 
     "<br><b>Employee Name:</b>" & 
     Form3.LastSubmit.Title &
     "<br>" &
     If(
     Len(LaptopMakeTxt.Text) > 0,
     "<b>Laptop Make: </b>" & 
     Form3.LastSubmit.LaptopMake &
     "<br>"
     ) & 
     If(
     Len(LaptopModelTxt.Text) > 0,
     "<b>Laptop Model: </b>" & 
     Form3.LastSubmit.LaptopModel &
     "<br>"
     ) & 
     If(
     Len(DesktopMakeTxt.Text) > 0,
     "<b>Desktop Make: </b>" &
     Form3.LastSubmit.DesktopMake &
     "<br>"
     ) & 
     "Regards<br><br>"
    );
    Navigate(Success)

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • Dave-ITMan Profile Picture
    on at

    Hi @WarrenBelz ,

    All sorted, thank you so much, you are "the man"! 

    Regards

    Dave

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard