Skip to main content

Notifications

Power Apps - Building 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 😞

  • Verified answer
    LaurensM Profile Picture
    LaurensM 12,510 on at
    Re: Using variables with OnSuccess

    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!

  • Jambou Profile Picture
    Jambou on at
    Re: Using variables with OnSuccess

    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
    LaurensM 12,510 on at
    Re: Using variables with OnSuccess

    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!

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,691

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 65,019

Leaderboard