cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Muzammil
Advocate I
Advocate I

ForAll Patch Collection to SharePoint List Keep looping first record from Collection - Issue

Hi I'm trying to Patch Collection created through Collect to SharePoint list but it keeps saving the only first record from Collection, code as follows;

 

ForAll(FishCatchCollection, Patch('Daily Fish Catch Detail', Defaults('Daily Fish Catch Detail'), {'Vessel Name': TextInput_VesselName.Text, 'Vessel Type': DD_VesselType.Selected, Guest: DD_Guest.Selected, 'Captain Name': TextInput_Captain.Text, Hail: Value(TextInput_Hail.Text), Unload: Value(TextInput_Unload.Text), 'In / Out': DD_InOut.Selected, Reason: DD_Reason.Selected, Comment: TextInput_Comment.Text}))

I attached PowerApps Screen and SharePoint list entry, as you can see PowerApps Collection have different records, on the other hand, SharePoint list only saving the first record and loop it as many times as the collection records are.

Please advise

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Muzammil 

I am assuming that all of the referenced controls (like TextInput_VesselName) are part of your Gallery.  

If that is the case, then referencing them in the way you are in your patch is going to only give you the first instance (record 1 in your case).

 

You need to reference the Controls as part of the Gallery:

ForAll(
   YouGalleryName.AllItems, 
      Patch('Daily Fish Catch Detail', 
         Defaults('Daily Fish Catch Detail'), 
         {'Vessel Name': TextInput_VesselName.Text, 
          'Vessel Type': DD_VesselType.Selected, 
          Guest: DD_Guest.Selected, 
          'Captain Name': TextInput_Captain.Text, 
          Hail: Value(TextInput_Hail.Text), 
          Unload: Value(TextInput_Unload.Text), 
          'In / Out': DD_InOut.Selected, Reason: 
          DD_Reason.Selected, 
          Comment: TextInput_Comment.Text}))

This will go through each item in your Gallery and patch it to the SharePoint list.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

8 REPLIES 8
RandyHayes
Super User
Super User

@Muzammil 

I am assuming that all of the referenced controls (like TextInput_VesselName) are part of your Gallery.  

If that is the case, then referencing them in the way you are in your patch is going to only give you the first instance (record 1 in your case).

 

You need to reference the Controls as part of the Gallery:

ForAll(
   YouGalleryName.AllItems, 
      Patch('Daily Fish Catch Detail', 
         Defaults('Daily Fish Catch Detail'), 
         {'Vessel Name': TextInput_VesselName.Text, 
          'Vessel Type': DD_VesselType.Selected, 
          Guest: DD_Guest.Selected, 
          'Captain Name': TextInput_Captain.Text, 
          Hail: Value(TextInput_Hail.Text), 
          Unload: Value(TextInput_Unload.Text), 
          'In / Out': DD_InOut.Selected, Reason: 
          DD_Reason.Selected, 
          Comment: TextInput_Comment.Text}))

This will go through each item in your Gallery and patch it to the SharePoint list.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Love it @RandyHayes, thank you!

Just tried it, work like a magic 🙂

Yes, all referenced controls (like TextInput_VesselName) are part of Gallery - true.

This is NOT working anymore!

@yuliamamonova 

Is there anything more to that statement?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

I found that the "yourGalleryName.AllItems" does not work for me.

YouGalleryName.AllItems

Instead the following works fine.

ForAll(
   YouGalleryName, 
      Patch('SP List Name', 
         Defaults('Sp List Name'), 
         {'Column Name': LineColumnName, 
          'Column Name2': LineColumnName2 
          }))

 LineColumn name is referred to the Column default value.

 

Cheers,

Alaleh

@Anonymous 

You cannot iterate a ForAll over a control. It needs a table source.  AllItems is a table source on a Gallery.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

Hi @RandyHayes ,

I agree with you, I use the different method which the result would be the same ae "Gallary.AllItems" . The All items, didn't work for me.

First for adding the repeating table row, I use the

BTN: OnSelect : Collect ( Collection Name,{ LineName:"",LineName2:""})

 

Second I save each row of gallery  to  collection

 in Gallery for the column I add the "ThisItem.LineName" to default property

Then create the Save an on select: Patch( collection Name,ThisItem,{LineName:TextInput.Text,LineName2:TextInput2.text})

 

then submit all the rows into list by click submit

Submit: For All(Collection Name,Patch(SPList Name,Defaults(SP List Name),{Column name in list:LineName,Column Name2:LineName2})

 

In this way after the submit all the rows will save in the list all in once.

 

Cheers,

Alale

 

 

@Anonymous 

Yes, and you can avoid all that work and just simply use a formula like this:

ForAll(
    yourGallery.AllItems,
    Patch(SPLListName, Defaults(SPListName),
        {ColumnNameInList : TextInput.Text,
         ColumnName2 : TextInput2.Text
        }
    )
) 
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,702)