cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Nate2182
Frequent Visitor

Error Handling - Patch/Submit Form (Multiple Forms)

Hello Community. I'm a new developer and am challenged with a situation. I have an App that has inputs from 4 different forms across 2 screens. Initially I tried SubmitForm(Form1);SubmitForm(Form2), etc but that gave me multiple rows for what I want all forms to be attributes of a single, new, record. Ideally I'd find a way to use this method but have it sumbitted as a single record because SubmitForm handles errors well. 

Second I've worked out how to Patch all of the form-fields as a single record but don't have any error handling like with SubmitForm. When I Preview the app and as an example, enter the same record ID twice, which is not allowed because my source requires unique values, it doesn't show me the error with the Patch. This error, along with other potential errors is a concern as I don't want users to go through the trouble of filling out all if the forms and thinking they submitted (via patch) but did not because of an undisclosed error.

Any help here would be appreciated. I've read of the Error function but can't seem to figure out how to piece it all together to show that the Patch didn't execute. 

 

Many Thanks,

-Nate

1 ACCEPTED SOLUTION

Accepted Solutions

Here is the code.  I removed my data fields.  I have the distinct pleasure in working in ag so everything I have to do requires offline capability.  So here is what happens:

 

For each item in my collection (SubmitData) it checks to see if the errors table was triggered.  If it isn't, then it will patch it to my sharepoint data set.  It will then count the total number of successes and create a notification.  Then, it will remove the successful items from the collection so the error items will remain stored to be resubmitted.  I don't really remember what counter2 is.  

 

ForAll(SubmitData,
If(IsEmpty(Errors('H2A Housing Inspection',
(Patch('H2A Housing Inspection',Defaults('H2A Housing Inspection'),
{})))),Collect(SuccessCount,Counter)));Notify(CountA(SuccessCount.Value)& " out of " &CountA(SubmitData.region5),NotificationType.Success);RemoveIf(SubmitData,Counter in SuccessCount.Value);Clear(SuccessCount);Set(Counter,1);ClearCollect(Counter2,Counter);

View solution in original post

12 REPLIES 12
rajatkush94
Frequent Visitor

Before patching the data into datasource:

 

If(Form1.Validate And Form2.Validate And Form3.Validate And Form4.Validate,Patch(),Notify())

 

Validate doesn't test for Unique Values in the source list though. It's only testing the validation requirements of the form before submission, correct?

Yes, Validate will check the form values are correct or not. Or if there is required column which entered.

What is the data source, if it SharePoint then in the column settings you can enforce unique values.

 

Else before patching you need to check:

Refresh(Datasource Name); CountRows(Filter(Datasource Name, UniqueColumnName = ValueEnteredInForm)=0, Patch(),Notify())

It's a SharePoint source where I already have it set on that field Enforce Unique Values. If I could submit all at once SubmitForm returns an error fine when a duplicate is entered. But because I'm having to Patch (across multiple forms), I'm not getting that error feedback after Patch complete. 

 

I like your second suggestion, and follow the logic of what it's supposed to do, but I cannot get it to work for some reason. Anything I'm missing there?

 

Refresh(RMTracker); CountRows(Filter(RMTracker,FWProject=FWProject_TI)=0,
Patch(RMTracker, Defaults(RMTracker),
{
    FWProject: FWProject_TI.Text,
    Title: Title_TI.Text
}))

 

 

 

Refresh(RMTracker); If(CountRows(Filter(RMTracker,FWProject=FWProject_TI.Text).FWProject)=0,
Patch(RMTracker, Defaults(RMTracker),
{
    FWProject: FWProject_TI.Text,
    Title: Title_TI.Text
}))

 

No luck here either

 

I don't like using forms.  I think a single form and patch is the way to go.  I'd suggest utilizing galleries, too.  It's a lot easier to work with, IMO.  The code I used is

 

ForAll, If,IsEmpty,Errors

 

So, basically, it cycles through my list.  If the errors formula is empty (errors creates a table with your errors), then patch it to your datasource.  If it doesn't create an error, then I remove it from my collection.  If it does, then an error message pops up and it remains in the collection to resubmit.  

Thanks for the response. I’d love to see a small-scale practical example if this. Can you share a functional syntax where you Submitted with this? I haven’t studied ForAll yet. 

Here is the code.  I removed my data fields.  I have the distinct pleasure in working in ag so everything I have to do requires offline capability.  So here is what happens:

 

For each item in my collection (SubmitData) it checks to see if the errors table was triggered.  If it isn't, then it will patch it to my sharepoint data set.  It will then count the total number of successes and create a notification.  Then, it will remove the successful items from the collection so the error items will remain stored to be resubmitted.  I don't really remember what counter2 is.  

 

ForAll(SubmitData,
If(IsEmpty(Errors('H2A Housing Inspection',
(Patch('H2A Housing Inspection',Defaults('H2A Housing Inspection'),
{})))),Collect(SuccessCount,Counter)));Notify(CountA(SuccessCount.Value)& " out of " &CountA(SubmitData.region5),NotificationType.Success);RemoveIf(SubmitData,Counter in SuccessCount.Value);Clear(SuccessCount);Set(Counter,1);ClearCollect(Counter2,Counter);

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (12,258)