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 / Button's action with m...
Power Apps
Unanswered

Button's action with multiple condition, help please?

(1) ShareShare
ReportReport
Posted on by 84
Hello and Happy New Year Everyone,
 
Am looking for some help in setting the actions for a button's OnSelect property. 
 
I have a Power Apps form with an Approval Status field. There are 4 choices for the Approval Status (Pending Approval, Initial Approval Complete, Final Approval Complete, Rejected). Current default is Pending Approval.
 
Here's what I'm trying to do:
1) When a new user submits a request, I need the app to send the user and cc: (to the 1st approver) an email , that his request was submitted for approval. Also the email should have the Group Name, Project Name and Amount field values from the form.
 
2) When the 1st approver updates the form with his approval, he changes the Approval Status to Initial Approval Complete. Upon clicking the Submit button, I need the app to send the Requester and the next approver an email with the decision, comment from the approver, Group Name, Project Name and Amount field values from the form. BUT if the decision is Rejected, I only need the app to send an email to the Requester with the same information above.
 
3) When the final approver receives the email from #2, he will update the form's Approval Status to Final Approval Complete or Rejected. Upon clicking the Submit button, I need the app to send the Requester and the previous approver an email with the decision, comment from the approver, Group Name, Project Name and Amount field values from the form.
 
4) Is it possible to have the Cancel button direct the Requester to Screen1 while if it's any of the Approvers, they go to Screen2?
 
Folks are probably going to say, why not use Power Automate? Well, I've tried but it's really hard and as it is, I'm struggling with Power Apps.
 
Please help? Thank you in advance!
Categories:
I have the same question (0)
  • bscarlavai33 Profile Picture
    752 Super User 2026 Season 1 on at
    What if you make a Float variable and set it using your expression instead of a Compose?
  • timl Profile Picture
    36,753 Super User 2026 Season 1 on at
    Hi  CU16101721-1
     
    It's possible to do this. Rather than add the email logic to the button's OnSelect property, the best thing to do is to add it to the OnSuccess property of your Form. By doing that, the email will be sent only when the record is saved successfully.
     
    The button's OnSelect property would store the values that you want to use in the email in variables before calling SubmitForm. By using the variables, you can more easily debug anything that goes wrong.
     
    UpdateContext({
        varGroupName: DataCardValueGroupName.Text,
        varProjectName: DataCardValueProjectName.Text,
        varAmount: DataCardValueAmount.Text,
        varRequesterEmail: DataCardValueRequesterEmail.Text,
        varApprovalStatus: DataCardValueApprovalStatus.Selected.Value,
        varComment: DataCardValueComment.Text
    });
    SubmitForm(Form1)
     
    In the OnSuccess property of your Form, you can then call Switch and send your email based on the approval status. The formula would look something like this:
     
    Switch(
        varApprovalStatus,
        "Pending Approval",
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been submitted for approval",
            "Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "approver@example.com"
            }
        ),
        
        "Initial Approval Complete",
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been initially approved",
            "Decision: Approved<br>Comment: " & varComment & "<br>Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "nextapprover@example.com"
            }
        ),
        
        "Final Approval Complete",
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been finally approved",
            "Decision: Approved<br>Comment: " & varComment & "<br>Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "previousapprover@example.com"
            }
        ),
        
        "Rejected",
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been rejected",
            "Decision: Rejected<br>Comment: " & varComment & "<br>Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "previousapprover@example.com"
            }
        )
    );
       
    To redirect the requester to Screen1, you would use this type of conditional logic.
    If(
        User().Email = DataCardValueRequesterEmail.Text,
        Navigate(Screen1, ScreenTransition.Fade),
        Navigate(Screen2, ScreenTransition.Fade)
    );
     
     
    Hopefully, this gives you the gist of how to approach this requirement.

     
  • CU16101721-1 Profile Picture
    84 on at
    Hi timl,
     
    Thank you so much for rapid response! I did exactly as you suggested however am not getting any emails. No syntax or other errors either so not sure how to troubleshoot it :(
     
    For the varRequesterEmail, I added the Created By in the form and changed the DataCardValue from Claims to Name then to Email (tried troubleshooting) but unfortunately no luck.
     
    Could the problem be the Approval Status? It defaults to "Pending Approval" but I think it's blank until the request is submitted successfully.
     
    SharePoint is all good as I see the test data.
     
    When you get a chance, can you please let me know where to look for the failed step(s)?
     
    Thank you again!
  • CU16101721-1 Profile Picture
    84 on at
    Hello Again timl,
     
    Just to give you an update ... I found a typo in the varRequesterEmail (my misspelling) so I fixed it. I then created a new request and still no email but I tested the Initial and Final Approval Complete status and I received the emails from both processes.
     
    The only issue now is, during the submission of a new request.
     
    Am hoping you can help again and thank you in advance!
  • timl Profile Picture
    36,753 Super User 2026 Season 1 on at
    Thanks for the update , I'm glad you're making progress.
     
    To troubleshoot this, I'd suggest Notifying varApprovalStatus before/or within the call to Switch. That way, you can inspect the value and figure out if it's calling the correct branch to send the email.
     
    Notify("varApprovalStatus: " & varApprovalStatus);
    Switch(
        varApprovalStatus,
        "Pending Approval",
        Notify("Sending Email for Pending Approval status...");
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been submitted for approval",
            "Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "approver@example.com"
            }
        ),
        
        "Initial Approval Complete",
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been initially approved",
            "Decision: Approved<br>Comment: " & varComment & "<br>Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "nextapprover@example.com"
            }
        ),
        
        "Final Approval Complete",
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been finally approved",
            "Decision: Approved<br>Comment: " & varComment & "<br>Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "previousapprover@example.com"
            }
        ),
        
        "Rejected",
        Office365Outlook.SendEmailV2(
            varRequesterEmail,
            "Your request has been rejected",
            "Decision: Rejected<br>Comment: " & varComment & "<br>Group Name: " & varGroupName & "<br>Project Name: " & varProjectName & "<br>Amount: " & varAmount,
            {
                Cc: "previousapprover@example.com"
            }
        )
    );
     
  • CU16101721-1 Profile Picture
    84 on at
    Hi timl,
     
    I added the notification and upon Submit, it came back with the below.
     
     
    I thought about adding IsBlank in the Switch but wouldn't that break the Initial and/or Final Approval Complete?
     
    Switch(
        IsBlank(varProjectApprovalStatus),
        //"Pending Approval",
        Office365Outlook.SendEmailV2(
  • CU16101721-1 Profile Picture
    84 on at
    Hi timl,
     
    Just wondering, maybe the first line in the Switch statement should be changed to "blank"?
     
    Can you please help me update the Switch from "Pending Approval" to "blank" without affecting the rest of the statuses?
     
    Thank you in advance!
     
    Switch(
        varApprovalStatus,
        "Pending Approval",
        Notify("Sending Email for Pending Approval status...");
     
     

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

#2
Haque Profile Picture

Haque 314

#3
Kalathiya Profile Picture

Kalathiya 234 Super User 2026 Season 1

Last 30 days Overall leaderboard