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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using variables with O...
Power Apps
Answered

Using variables with OnSuccess

(0) ShareShare
ReportReport
Posted on by

I have a form with 2 buttons, SUBMIT and SAVE. I want it to send email to a user based on the button that is used, so if they click the SUBMIT button an email would go out saying a New form was submitted.  If they click the SAVE button, it would send an email saying the form was Updated. It's currently sending out 2 emails, I only want it to send one or the other.

 

On the SUBMIT button I have this for OnSelect property:

Set(varFormStatus,"Saved"); SubmitForm(EditForm); Notify("The form was saved successfully",NotificationType.Success,0)

 

On the SAVE button I have this for OnSelect property:
Set(varFormStatus,"Updated"); SubmitForm(EditForm); Notify("The form was saved successfully",NotificationType.Success,0)

 

On the EditForm I have this on the OnSuccess property:

If(varFormStatus, "Pending";Office365Outlook.SendEmailV2(
"myemail@EMAIL.com",
"New Reallocation Request",
"Hello " & User().FullName &
"<a href='https://apps.powerapps.com/play/e/default-3e1c8459-76b0-41e2-9384-08b8e6adadbc/a/ab1b-0fe6287f23ca?tenantId=3e1c86adadbc&hint=f70326e4-b7&sourcetime=2023-08-18%2014%3A31%3A04Z'> Form Link ,</a>"

));
If(varFormStatus, "Updated";Office365Outlook.SendEmailV2(
"myemail@EMAIL.com",
"Reallocation Request Updated",
"Hello " & User().FullName &
"<a href='https://apps.powerapps.com/play/e/default-3e1c8459-76b0-41e2-9384-08b8e6adadbc/a/ab1b-0fe6287f23ca?tenantId=3e1c86adadbc&hint=f70326e4-b7&sourcetime=2023-08-18%2014%3A31%3A04Z'> Form Link ,</a>"

));

 

It's sending out both emails 😞

Categories:
I have the same question (0)
  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Jambou,

     

    With an If() statement you will have to provide the full condition:

     

    If(
     //see = "Updated"
     varFormStatus = "Updated",
     true,
     //false is optional, remove the comma after true to only provide a true parameter
     false
    )

     

    What I would recommend is using a Switch statement:

     

    Switch(
     varFormStatus,
     "Pending",
     EMAIL_CODE_PENDING_HERE,
     "Updated",
     EMAIL_CODE_UPDATED_HERE
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • Jambou Profile Picture
    on at

    Hi @LaurensM ,

     

    This works great, using Switch is a much better way to do this.  Thank you!

     

    If I have a "Status" choice list field in my SharePoint data source, is there a way to update that column at the same time when the button it clicked?  So for example, if the Updated button is clicked, it would send the email and also update the "Status" field in SharePoint?

     

    Is this possible?

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Jambou,

     

    That is certainly possible, you will have to add a patch function to your Switch value:

    Switch(
     varFormStatus,
     "Pending",
     Office365Outlook.SendEmailV2(),
     "Updated",
     //Add a Semicolon after your SendEmailV2() to add an additional function
     Office365Outlook.SendEmailV2();
     Patch(
     //Change DataSource to the correct name
     DataSource,
     Self.LastSubmit,
     //Change Updated to the correct choice text
     {Status: {Value: "Updated"}}
     )
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 529 Most Valuable Professional

#2
Haque Profile Picture

Haque 230

#3
Kalathiya Profile Picture

Kalathiya 217 Super User 2026 Season 1

Last 30 days Overall leaderboard