cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
WI-User-01
Helper I
Helper I

Issue with Submit Form and Patch Repeating Gallery via OnSuccess

I'm following Shane Young's YouTube guide on using custom forms to look like InfoPath and am running into a hiccup. @Shanescows

 

Source:  https://youtu.be/5vVFgaEBYuM

I've got the form and the gallery working just fine and I'm using the OnSuccess of the Form to patch the repeating Gallery to my SQL database. 

What's happening is this...  If there is more than 1 entry in the gallery, the data writes properly to the collection I save it to.  View Collections shows accurate data.  When the OnSuccess patches the collection to the SQL database, the first record in the collection is repeated into SQL, instead of the actual data being written.

 

Here's an overview:

1. App loads, Form autopopulates with user and a unique request number (working fine)

2. Gallery has a bunch of fields and a save button.  Clicking the save button saves the item to a collection.  Each time they click Save, it saves that item to the collection (working fine)

3. User clicks the Submit button to submit the data they've just entered in.  If they've only entered 1 item, all is well.  data in form and data in Gallery/Collection is written just fine.  If they've entered more than 1 item into the Gallery, only the first item in the collection is written, but, if there are 5 items, the first item's data is written 5 times to SQL.  (not working)

 

 

Here's a snippet of my patch code in the OnSuccess...  I've edited it for privacy, but that's the jist of it.  The bold parts were changed from actual names to general names.

ForAll(Collection, Patch('[SQL Table]', Defaults('[SQL Table]'), {List of about 15 fields}));Clear(Collection)

 

Any ideas where my glitch is?  

 

1 ACCEPTED SOLUTION

Accepted Solutions
WI-User-01
Helper I
Helper I

Good news!

I figured out my own issue after a day or so of going over it...

 

In my OnSuccess code, specifically, the list of 15+ fields I am patching to SQL, I was referencing the Gallery input fields, instead of the Collection field names.  Once I realized that and changed the field names in the code to reference the right data, it is now working great.

 

Thought I'd come back and update the post in case anyone else experiences this too.  Have a good day.

View solution in original post

2 REPLIES 2
WI-User-01
Helper I
Helper I

Good news!

I figured out my own issue after a day or so of going over it...

 

In my OnSuccess code, specifically, the list of 15+ fields I am patching to SQL, I was referencing the Gallery input fields, instead of the Collection field names.  Once I realized that and changed the field names in the code to reference the right data, it is now working great.

 

Thought I'd come back and update the post in case anyone else experiences this too.  Have a good day.

View solution in original post

Glad you got it. Sorry, I was slow to respond. 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

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 (74,149)