Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

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!

 

  • Dave-ITMan Profile Picture
    on at
    Re: If Statement in body of email

    Hi @WarrenBelz ,

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

    Regards

    Dave

  • Verified answer
    WarrenBelz Profile Picture
    146,700 Most Valuable Professional on at
    Re: If Statement in body of email

    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
    Re: If Statement in body of email

    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 

  • WarrenBelz Profile Picture
    146,700 Most Valuable Professional on at
    Re: If Statement in body of email

    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

  • mmbr1606 Profile Picture
    12,121 Super User 2025 Season 1 on at
    Re: If Statement in body of email

    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

  • KRider Profile Picture
    577 Super User 2024 Season 1 on at
    Re: If Statement in body of email

    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! 😄 

     

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,700 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard