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 / Help please with an em...
Power Apps
Answered

Help please with an email and submit button field condition?

(2) ShareShare
ReportReport
Posted on by 84
Hi There,
 
I have the code below as part of sending an email to the requester. It's somewhat working but I would like add a condition to show the "actual" approval status by the Initial Approver and the Final Approver. Currently, it's only picking up the last approval status which is misleading.
 
Also, what am I missing for the varInitialApprover and varFinalApprover as it is blank in the email?
 
        <b>Approval/Rejection Information:</b><br>
        <b>Initial Approval/Rejection Status:</b> " & varProjectApprovalStatus & "<br>
        <b>Initial Approval/Rejection Date:</b> " & varInitialDate & "<br>
        <b>Initial Approval/Rejection By:</b> " & varInitialApprover & "<br>
        <b>Initial Approval/Rejection Comments:</b> " & varInitialComment & "<br><br>
 
        <b>Final Approval/Rejection Status:</b> " & varProjectApprovalStatus & "<br>
        <b>Final Approval/Rejection Date:</b> " & varFinalDate & "<br>
        <b>Final Approval/Rejection By:</b> " & varFinalApprover & "<br>
        <b>Final Approval/Rejection Comments:</b> " & varFinalComment & "<br><br>
 
 
Lastly, I have an Approval Status and a Submit button in my form, I would like to change the behavior of the button to disabled if the Approval Status is already set as Final Approval Complete or Rejected. I have this code now in the Display Mode property of the button but the problem is, it's automatically disabling the button before I can click on Submit.
 
If(DataCardValue10.Selected.Value = "Final Approval Complete", DisplayMode.Disabled, If(DataCardValue10.Selected.Value = "Rejected", DisplayMode.Disabled,DisplayMode.Edit))
 
Can you please help? Thank you in advance!
 
Categories:
  • WarrenBelz Profile Picture
    156,714 Most Valuable Professional on at
    Please supply the code for setting varInitialApprover and varFinalApprover as well as where and when you are using it.
    For the last one, you will need to test the data source content (I am assuming a Choice field here - if not you do not need .Value )
    If(
       ThisItem.'Approval Status'.Value = "Final Approval Complete" ||
       ThisItem.'Approval Status'.Value = "Rejected", 
       DisplayMode.Disabled,
       Parent.DisplayMode
    )
     
    ​​​​​​​Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
     
  • CU16101721-1 Profile Picture
    84 on at
    Hi Warren,
     
    Thank you so much for the response! The varInitialApprover and varFinalApprover is from another issue that I'm trying to workout and for that issue, "timl" is helping me out but please do not think this is a duplicate issue (just thought I would be upfront).
     
    Anyway, here's the code that I'm using from timl. Thank for the suggestion on the last item, I will test it now.
     
    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"
            }
        )
    );
  • CU16101721-1 Profile Picture
    84 on at
    So sorry, Warren, I meant to share the link on the other issue. 
     
  • CU16101721-1 Profile Picture
    84 on at
    Hi Warren,
     
    For the last item, yes it is a choice field. I just updated the Submit button's code to your suggestion and it came back with a few errors.
     
    Here they are:
  • Verified answer
    WarrenBelz Profile Picture
    156,714 Most Valuable Professional on at
    Dealing with the second one, I now assume that the Submit button is outside the Form - hence the error on ThisItem. The other errors are all related to the fact that this does not return the required field value. So assuming you are selecting the record for the Form from a Gallery
    If(
       GalleryName.Selected.'Approval Status'.Value = "Final Approval Complete" ||
       GalleryName.Selected.'Approval Status'.Value = "Rejected", 
       DisplayMode.Disabled,
       Parent.DisplayMode
    )
    The whole point is that you need to compare the value in the current field that has been saved or (as you have discovered) if you compare with the control value that has been input, you cannot save the record as the button is immediately disabled.
    For the first one, you still have not posted how and where varInitialApprover and varFinalApprover are set, nor is there any mention of them in the other post.
  • CU16101721-1 Profile Picture
    84 on at
    Hi Warren,
     
    My apologies ...
     
    varInitialApprover and varFinalApprover are set from the UpdateContext and from there it gets its value from the data card in the form fields (Initial Approver and Final Approver (both are person column/display name)).
     
    As for the below, the form is not from a Gallery selection. Just a blank form that the user goes to. 
     
    Should I place the buttons inside the form and retest with your previous suggestion? Please let me know?
     
    If(
       GalleryName.Selected.'Approval Status'.Value = "Final Approval Complete" ||
       GalleryName.Selected.'Approval Status'.Value = "Rejected", 
       DisplayMode.Disabled,
       Parent.DisplayMode
    )
  • WarrenBelz Profile Picture
    156,714 Most Valuable Professional on at
    I need the actual code you are using to set these two variables and also where/when you are using it. Your posted question was why the Variables are blank and to see this, how and when they are set needs to be investigated.
    The other confusing matter is what you have now posted regarding this being a new record form. Why do you want the button disabled as there are no circumstances requiring this (if the Form is only for new records, then the button should always be active) - I was assuming it also displayed existing records, hence the test against the current data.
  • CU16101721-1 Profile Picture
    84 on at
    Hi Warren,
     
    I'm so sorry for the back and forth, please note that I'm only a business user by trade so in short, do not really know what I'm doing :( but I appreciate your patience in helping me out.
     
    varInitialApprover/varFinalApprover code = I do not know where else to get the code as I only have the Update Context in the OnSelect of the Submit button which is where the variables are created. I expanded the Update Context code provided by timl to have other fields. The Submit button is in the New/Edit form where a user submits a request and also where the approvers go into Approve or Reject a request. 
     
    Here are the steps in the app:
    1) A user submits a new request then the user will receive a confirmation email with a cc: Initial Approver (hard-coded to the my email for now). Request's Approval Status updates to Pending Approval.
     
    2) Initial Approver = updates the form's Approval Status to Initial Approval Complete (if approved) or Rejected. After the Initial Approver clicks on Submit, the app is suppose to send another email to inform the Requester of the new status and cc's: to the Final Approver (hard-coded to my email for now). 
    Request's Approval Status updates to Initial Approval Complete.
     
    3) Final Approver = updates the form's Approval Status to Final Approval Complete (if approved) or Rejected. After the Initial Approver clicks on Submit, the app is suppose to send another email to inform the Requester of the new status and cc's: to the Initial Approver (hard-coded to my email for now).
    Request's Approval Status updates to Final Approval Complete.
     
    Submit Button's OnSelect Property:
    UpdateContext({
        varPortfolio: DataCardValue6.Selected.Value,
        varProjectName: DataCardValue7.Text,
        varRequestedAmount: DataCardValue23.Text,
        varRequesterEmail: DataCardValue12.Selected.Email,
        varProjectApprovalStatus: DataCardValue10.Selected.Value,
        varInitialComment: DataCardValue8.Text,
        varFinalComment: DataCardValue18.Text,
        varInitialDate: DataCardValue24.SelectedDate,
        varFinalDate: DataCardValue9.SelectedDate,
        varInitialApprover: DataCardValue25.Selected.DisplayName,
        varFinalApprover: DataCardValue19.Selected.DisplayName
    });
     
    Form's OnSuccess Property:
    Notify("varProjectApprovalStatus: " & varProjectApprovalStatus);
    Switch(
        varProjectApprovalStatus,
        "Pending Approval",
        Notify("Sending Email for Pending Approval status...");
        Office365Outlook.SendEmailV2(
            varRequesterEmail ......
     
    Or 4) Either of the approvers can also Reject a request. The Rejection step is what prompted me to create this post.
     
    Because if the Initial Approver's decision = approved but the Final Approver's decision = rejected, I would like the app to send an email to the user with the following information where it will show the requester, what was the Initial Approver's action vs the Final Approver's action.
     
    This is why in the below, I have 2 sections below which is part of the Rejection email and would like the fields to dynamically populate.
     
            <b>Approval/Rejection Information:</b><br>
            <b>Initial Approval/Rejection Status:</b> " & varProjectApprovalStatus & "<br>
            <b>Initial Approval/Rejection Date:</b> " & varInitialDate & "<br>
            <b>Initial Approval/Rejection By:</b> " & varInitialApprover & "<br>
            <b>Initial Approval/Rejection Comments:</b> " & varInitialComment & "<br><br>
     
            <b>Final Approval/Rejection Status:</b> " & varProjectApprovalStatus & "<br>
            <b>Final Approval/Rejection Date:</b> " & varFinalDate & "<br>
            <b>Final Approval/Rejection By:</b> " & varFinalApprover & "<br>
            <b>Final Approval/Rejection Comments:</b> " & varFinalComment & "<br><br>
     
    Apologies for the long-winded response, in short, the varInitialApprover & varFinalApprover are only used in the OnSuccess property of the form for the app to send emails based on the Approval Status. The same goes for all the variables in the Update Context property.
     
    Thank you so much again, Warren!
     
     
     
  • CU16101721-1 Profile Picture
    84 on at
    Hi Warren,
     
    The the last issue in the list is resolved! YAY!, thank you, thank you so much! After reading your last comment, it was then I realized that you are correct about "coming from a gallery ..." so I updated the Display Mode and it's working like a charm.
     
    Thank you again!
     
    If(
       GalleryName.Selected.'Approval Status'.Value = "Final Approval Complete" ||
       GalleryName.Selected.'Approval Status'.Value = "Rejected", 
       DisplayMode.Disabled,
       Parent.DisplayMode
    )
  • WarrenBelz Profile Picture
    156,714 Most Valuable Professional on at
    Are you running this code before or after the SubmitForm() ? It needs to be before submission or the controls values will no longer be valid (which is why I have been asking this question from the start)
    UpdateContext(
       {
          varPortfolio: DataCardValue6.Selected.Value,
          varProjectName: DataCardValue7.Text,
          varRequestedAmount: DataCardValue23.Text,
          varRequesterEmail: DataCardValue12.Selected.Email,
          varProjectApprovalStatus: DataCardValue10.Selected.Value,
          varInitialComment: DataCardValue8.Text,
          varFinalComment: DataCardValue18.Text,
          varInitialDate: DataCardValue24.SelectedDate,
          varFinalDate: DataCardValue9.SelectedDate,
          varInitialApprover: DataCardValue25.Selected.DisplayName,
          varFinalApprover: DataCardValue19.Selected.DisplayName
      }
    );

    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee

     
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 352 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 323

#3
Mohsin Ali Profile Picture

Mohsin Ali 226

Last 30 days Overall leaderboard