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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Trying to update a Sha...
Power Apps
Answered

Trying to update a Sharepoint list from a gallery and it is creating new records instead of updating existing records

(0) ShareShare
ReportReport
Posted on by 380

I have a 2 Sharepoint lists which are linked by a number field called "tripid"

 

The first list is Trips and contains details of people's field trips, the second list is called TripDetails and it contains a record for every day the person is out on the trip - this could be just 1 day or up to 10 days - both lists have the tripid field which is how I link them in my app.

 

I have a form for the Trip and it's Items property is set to a Gallery that the user goes to first to select which trip they want to update. Next to the form on the same screen I have a Gallery for TripDetails and it's Items property is also set to the Gallery. I can easily update data in the Form by just using SubmitForm(TripForm2_3) but I want to also update the TripDetails.

 

I have put a button on the bottom of the screen and it's On Select property is:

Patch(TripDetails,
ForAll(Gallery6_4.AllItems As _item,
{ tripid: _item.tripid,
tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
destination: _item.TextInput2_25.Text,
activity: _item.TextInput2_27.Text,
accomodation: _item.TextInput2_29.Text,
localcontact: _item.TextInput2_28.Text,
callintimes: _item.TextInput2_30.Text,
hoursworked: _item.TextInput2_31.Text
}
)
)

I can go the Gallery and make changes to the data but when I try to update by clicking the button my code is adding new data to the list instead of just updating the existing data, so if I had 5 rows in the Gallery after I click the button I end up with 10 rows - how can I just UPDATE and not create new (I thought it would only create new records if I used (Defaults)??

 

any help greatly appreciated

Categories:
  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @bobgodin ,

    Try and get th SP ID back (if you do not have it in the gallery already)

    Patch(
     TripDetails,
     ForAll(
     Gallery6_4.AllItems As _item,
     With(
     {
     _ID:
     LookUp(
     TripDetails,
     tripid = _item.tripid
     ).ID
     },
     {
     ID: _ID,
     tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
     destination: _item.TextInput2_25.Text,
     activity: _item.TextInput2_27.Text,
     accomodation: _item.TextInput2_29.Text,
     localcontact: _item.TextInput2_28.Text,
     callintimes: _item.TextInput2_30.Text,
     hoursworked: _item.TextInput2_31.Text
     }
     )
     )
    )

     

    Please click Accept as solution 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 Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • bobgodin Profile Picture
    380 on at

    Hi @WarrenBelz thank you for that - I copied and pasted your code exactly into my app and it accepted it without any red lines but when I ran it it came back with a "Network error using Patch function. The requested operation is invalid" and didn't update anything

  • bobgodin Profile Picture
    380 on at

    Hi @WarrenBelz I decided that I should actually add a textLabel into the Gallery for the ID field so did this and renamed it to "ID" and added a bit more code and its working now

     

    I hadn't realised how tricky it can be to do a simple update - here's my updated code - is there anything superfluous in there now?:
    thanks 🙂

  • bobgodin Profile Picture
    380 on at

     

    Patch(
     TripDetails,
     ForAll(
     Gallery6_4.AllItems As _item,
     With(
     {
     _ID:
     LookUp(
     TripDetails,
     ID = Value(_item.ID.Text)
     ).ID
     },
     {
     ID: _ID,
     tripid: Value(_item.TextInput2_26.Text),
     tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
     destination: _item.TextInput2_25.Text,
     activity: _item.TextInput2_27.Text,
     localcontact: _item.TextInput2_28.Text,
     accomodation: _item.TextInput2_29.Text,
     callintimes: _item.TextInput2_30.Text,
     hoursworked: _item.TextInput2_31.Text
     }
     )
     )
    )
  • Verified answer
    WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @bobgodin .

    If you have the ID already in the Gallery, there is no need for any of that

    Patch(
     TripDetails,
     ForAll(
     Gallery6_4.AllItems As _item,
     {
     ID: _item.ID,
     tripid: Value(_item.TextInput2_26.Text),
     tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
     destination: _item.TextInput2_25.Text,
     activity: _item.TextInput2_27.Text,
     localcontact: _item.TextInput2_28.Text,
     accomodation: _item.TextInput2_29.Text,
     callintimes: _item.TextInput2_30.Text,
     hoursworked: _item.TextInput2_31.Text }
     }
     )
    )

     

    Please click Accept as solution 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 Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • bobgodin Profile Picture
    380 on at

    thanks @WarrenBelz that has fixed the problem but now I seem to have another problem in my app - should I create a new post?  thanks

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @bobgodin ,

    Yes if it is unrelated to this, a new post is the appropriate action.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard