Skip to main content

Notifications

Power Apps - Power Apps Experimental Features
Suggested answer

Validate form fields when using patch?

(0) ShareShare
ReportReport
Posted on by 12
Hi all!
 
Hoping somone can offer some advice here.
 
I have a Form that is split over 2 tabs on my Powerapp.    In order to submit the form, I use the Patch function.
I normally use the SubmitForm() function and it automatically validates the fields and you get the relevant errors in red text(see screenshot:)
 
 
My question is this: 
 
How do I validate the same way when using the PATCH function? 
 
Is it possible to run the same validation as the SubmitForm() before doing the patch?
 
Thanks in advance
 
 
 
Here's my code:
 
//Old method of submit form
//SubmitForm(FormShiftData);
 
Patch('MWOS_Data_LN', Defaults('MWOS_Data_LN'), FormShiftData.Updates,FormRejectData.Updates);
 
If(
     // check if there were any errors when the test score was submitted
     !IsEmpty(Errors('MWOS_Data_LN')),
     // if true, show any error message
     Notify(
         Concat(Errors('MWOS_Data_LN'), Column&": "&Message),
         NotificationType.Error
     ),
     // else, go to success screen
     ResetForm(FormShiftData);
     ResetForm(FormRejectData);
     Refresh(ExistingRecordsView);
     Navigate(ViewMainScreen,ScreenTransition.Fade);
 
 )
  • WarrenBelz Profile Picture
    WarrenBelz 145,445 on at
    Validate form fields when using patch?
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    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
  • WarrenBelz Profile Picture
    WarrenBelz 145,445 on at
    Validate form fields when using patch?
    Hi @StuDev,
    Unfortunately, you cannot have it both ways - if it passes the test, then there are no errors to display. You would need to go back to what you had before and capture any errors, This would also mean some manual action to capture missing fields.
  • StuDev Profile Picture
    StuDev 12 on at
    Validate form fields when using patch?
    Thanks Warren.
     
     
    Do I need to incorporate the error handling for the patch function after the form validation?
     
     
    Pseudo code in BOLD red
     
     
    IF (FormShiftData.Valid && FormRejectData.Valid) {
    //true - form is valid, now do the patch and the error handling
     
    Patch('MWOS_Data_LN', Defaults('MWOS_Data_LN'), FormShiftData.Updates,FormRejectData.Updates);
     
    If(
         // check if there were any errors when the test score was submitted
         !IsEmpty(Errors('MWOS_Data_LN')),
         // if true, show any error message
         Notify(
             Concat(Errors('MWOS_Data_LN'), Column&": "&Message),
             NotificationType.Error
         ),
         // else, go to success screen
         ResetForm(FormShiftData);
         ResetForm(FormRejectData);
         Refresh(ExistingRecordsView);
         Navigate(ViewMainScreen,ScreenTransition.Fade);
     
     )
    ELSE
    //show the required fields - Will it do this automatically? or do I need to anything?
     
    }
  • Suggested answer
    WarrenBelz Profile Picture
    WarrenBelz 145,445 on at
    Validate form fields when using patch?
    Hi @StuDev​​​​​​​
    Try Form.Valid
    If(
       FormShiftData.Valid && FormRejectData.Valid,
       Patch(
          'MWOS_Data_LN', 
          Defaults('MWOS_Data_LN'), 
          FormShiftData.Updates,
          FormRejectData.Updates
       ),
       Notify(
          "Errors . . . ",
    	  NotificationType.Error
       )
    )

    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

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,445

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,741

Leaderboard

Featured topics