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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to add an error ch...
Power Apps
Unanswered

How to add an error check to a button function

(0) ShareShare
ReportReport
Posted on by 381

Hi again.

My PowerApp is not writing to my SharePoint list that is the connected data source.  I discovered the reason is there was an error with one of the fields not being entered correctly.  This error was not caught because the submit button will not only submit the form, but will also launch another powerapp- causing the error to be missed before the launch.  How can I put in an error check before the launch is done?

Currently,

Button2 is made visible when the user chooses "Yes" on the dropdown (Warranty Claim?_DataCard1).  The button is set to SubmitForm(Form1); Launch("web address to another PowerApp edit form").

Button3 is made visible when the user chooses "No" on the same dropdown above.  The button is set to SubmitForm(Form1).

The issues I am having here is after clicking Submit (Button3), I get a pink error across the top saying that Title is required (I dont have a Title field being used).  Also, I am getting an Action error for OnSelect- SubmitForm(Form1).  I dont understand why.

The Form (Form1) is set to ResetForm(Form1) OnSuccess.

 

Thanks,

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @MShelnutt 

    This is the purpose of the OnSuccess and OnFailure actions of the EditForm.

    Move any actions you want to happen when the submit is successful to the OnSuccess action - such as your Launch function.

    Also, it is advisable to pre-validate your form information before submitting.  This is usually done by deactivating (displaymode - Disabled) the button where you submit until the form is accurately completed.

     

    I hope this is helpful for you.

  • MShelnutt Profile Picture
    381 on at

    @RandyHayes  I appreciate your time.  I cannot put the Launch function in the Form OnSuccess action, as only one of the submit buttons will do that action.  The other submit button will only submit and reset.

     

    I have changed the two buttons' DisplayMode to Disabled.

     

    I still have Button 3 with an error for its Action OnSelect being SubmitForm(Form1).  The red X says Title: Field 'Title' is required.  I am at a loss on this.

     

    MShelnutt_0-1609947351548.png

     

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @MShelnutt 

    So yes, you can still do this (and absolutely should based on my first message).  You really don't want to do actions that are based on the success of the submit without validating that it was actually a success.

    For the one button that should launch, I would add something like: UpdateContext({lclDoLaunch:true});  SubmitForm(yourForm)

    Then in the OnSuccess, change the formula to : If(lclDoLaunch, Launch(....))

     

    Now, that should solve the first issue of launching even when there is an error.  For the next issue, your SharePoint List has a Title column.  By default, it is required.  You can either change the column to be not required or you can supply a value for the Title column in your EditForm.  That will resolve that issue as well.

     

  • MShelnutt Profile Picture
    381 on at

    @RandyHayes Ok, I have done all you suggested and just done a test run with Button3 (just submit form), and the more complex Button2 (with the UpdateContext), but I cannot click the buttons (you suggested to disable the view?)  I can see it, but it is grayed out and not clickable.

     

     

  • MShelnutt Profile Picture
    381 on at

    I changed the DisplayMode back to Edit and all is working correctly now.  So other than that suggestion, everything worked.  Thank you!

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @MShelnutt 

    I believe you might have misunderstood my point about disabling the buttons.  The purpose was to utilize a formula on the displayMode properties that validates the form before allowing the user to submit.  This avoids executing the submit on an invalid form and thus getting nasty banner errors in the app.

     

    If you have no complex validation for your form, then simply put the following into all three of the DisplayMode properties : If(Form1.Valid, Edit, Disabled)

    The built in validation of a form will already validate for required fields.

     

    If, however, you have more complex validation (I'll use the example that a specific field in the form must be 4 characters long - let's call it AccountCode), then you can extend this out.

    Since you are dealing with 3 buttons that should technically not be "available" until the form is complete, I would suggest (instead of copying and pasting the same formula, and then maintaining it, in three places) placing a Toggle control on the screen (let's call it tglFormValid)

    In the Default property of the toggle, set the following formula:

     

     

    Form1.Valid &&
    (Len(Form1.Updates.AccountCode)=4)

     

    Now, for the DisplayMode property of the 3 buttons, set the formula to the following:

       If(tglFormValid.Value, Edit, Disabled)

     

    You can set the visibility of the toggle to false so it is not seen by users.

    When the condition in the default property ( form is valid AND the length of the AccountCode is 4 characters), then the toggle will change to true/on.  The formula in the DisplayMode on the buttons just looks at that toggle value.

    Advantage, your validation formula is only in one place.  If you need to change anything, you only do it in one place.

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard