Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Having trouble updating rows in a gallery

Posted on by 359

I have a Gallery which displays a summary of all records in my Sharepoint lists. From that Gallery I can select a record and navigate to a different screen which has an Edit Form and a Gallery in it. The Form and the Gallery are linked by a "tripID' field which exists in both lists.

 

When I click on the edit icon from the main Gallery the OnSelect property updates a collection which I continue to work with:

ClearCollect(
 colDetails,
 Filter(
 TripDetails,
 tripid = (Gallery5.Selected.tripid)
 )
);

 On the next screen the Gallery's Items property is simply:

SortByColumns(colDetails,"tripdate")

 In this Gallery I need to add days to an existing trip or change dates and other information about the trip. I have an add row icon and it's properties are:

Patch(
 colDetails,
 Defaults(colDetails),
 {
 tripid: Value(TextInput2_26.Text),
 tripdate: Gallery6_4.Selected.tripdate,
 destination: TextInput2_25.Text,
 activity: TextInput2_27.Text,
 localcontact: TextInput2_28.Text,
 accomodation: TextInput2_29.Text,
 callintimes: TextInput2_30.Text,
 hoursworked: TextInput2_31.Text
 }
);

I can add a row and edit the data but sometimes if I change the date it will change one of the other existing dates and I have to change it back or delete that row and re-add one. That's a minor problem compared with my bigger problem which is when I come to submit the records to my datasource it doesn't work - here is the code for that:

ForAll(
 colDetails,
 Patch(
 TripDetails,
 LookUp(TripDetails,ID=Value(TextInput2_32.Text)),
 {
 tripid: tripid,
 tripdate: DateValue(DatePicker1_1.SelectedDate),
 destination: TextInput2_25.Text,
 activity: TextInput2_27.Text,
 accomodation: TextInput2_29.Text,
 localcontact: TextInput2_28.Text,
 callintimes: TextInput2_30.Text,
 hoursworked: TextInput2_31.Text
 }
 )
 )
);

I don't get any error messages but it doesn't add any new records that I have added to the collection however any edits that I make to existing records do update the Sharepoint list.  I think I am missing something obvious but can't work out what it is - can anyone help please?

Categories:
  • Verified answer
    bobgodin Profile Picture
    bobgodin 359 on at
    Re: Having trouble updating rows in a gallery

    thank you so much for your help Warren and it was great talking to you and picking up those other tips

  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 143,591 on at
    Re: Having trouble updating rows in a gallery

    @bobgodin ,

    OK - So is it the day after the latest trip in the whole list or do you have a field for the user and you want it to be the day after their last trip. This may be easier on Teams - if you PM me your email, I can send an invitation.

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Having trouble updating rows in a gallery

    @WarrenBelz It's not based on destination, no.

     

    The user will find a trip they have already done and will copy it from another screen and the dates will be whatever the last trip was and they will want to just change the dates - the rest of the info will probably be the same - that saves them having to enter all fields again. They could also create a brand new trip and add the days and dates and then save the trip and then come back later an add a day or change the days depending on weather etc..

     

    So the dates could be anything but always in the future as they are planning for a field trip they are going on - could be tomorrow, next week, next month even.

     

    Yes I too am in Rocky Warren

  • WarrenBelz Profile Picture
    WarrenBelz 143,591 on at
    Re: Having trouble updating rows in a gallery

    @bobgodin ,

    OK - how do you identify the record set to get the latest trip date - is it based on Destination ? BTW where are you based - you data is very close to home for me.

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Having trouble updating rows in a gallery

    @WarrenBelz please see attached screenshot of my Gallery showing tripdates 20/12/22 - 24/12/22

    If I choose to add a day I would like it to be whatever the latest tripdate is + 1 day - so in this case the 25/12/22 and then 26/12/22 and so on...thank you!

  • WarrenBelz Profile Picture
    WarrenBelz 143,591 on at
    Re: Having trouble updating rows in a gallery

    @bobgodin ,

    I am a bit unclear on what date you want to use to add days to - currently you are using a Date Picker value.

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Having trouble updating rows in a gallery

    @WarrenBelz I found that the following code works when patching the collection (the OnChange property):

    Patch(
     colDetails,ThisItem,
     {destination: TextInput2_25.Text}
    )

    and I figured out that if I left out the ID field when adding a new record to the collection the Patch to the SP list would just update existing records and patch a new record and create a new ID in the SP list....these blocks of code are working:

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

    the only thing that is not working correctly is when adding a new record to the collection it sets the date to the same as the last date in the Gallery but when I change it to "lastday+1" it changes one of the other records - how can I force it to make the new record have a tripdate which is the latest date+1 day?

     

    my code on the OnChange property of the tripdate DatePicker control:

    Patch(
     colDetails,
     ThisItem,
     {tripdate: DateValue(DatePicker1_1.SelectedDate)}
    )
  • WarrenBelz Profile Picture
    WarrenBelz 143,591 on at
    Re: Having trouble updating rows in a gallery

    @bobgodin ,

    This code should work assuming you have the ID in your TextInput2_32 (you might consider some control naming protocols here is make life easier)

    Patch(
     colDetails,
     LookUp(
     colDetails,
     ID = Value(TextInput2_32.Text)
     ),
     {destination: TextInput2_25.Text}
    )

    but the only way you are going to get the ID is after the SP record is created (or it simply will not Patch anything) and of course you are creating new record in the collection, which will not have an ID. So unless the record you are editing is in the original collection

    ClearCollect(
     colDetails,
     Filter(
     TripDetails,
     tripid = Gallery5.Selected.tripid
     )
    );

    you will not have an ID to refer to - so do you have any other unique identifying field in the collection - if so, use that for the Lookup.

     

    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
    bobgodin 359 on at
    Re: Having trouble updating rows in a gallery

    @WarrenBelz thank you Warren - it's not working but I haven't told you the full story and that's probably why...

    I need to update the records in the Gallery before I Patch to the SP List so I have this code on the OnChange property of the DatePicker and TextInput controls (this is for the destination column):

    Patch(
     colDetails,LookUp(colDetails,ID=Value(TextInput2_32.Text)),
     {destination: TextInput2_25.Text}
    )

    I know it's not working because after I make a change I can go and look at the collection and it hasn't changed so my code must be wrong - it's not giving me any errors though...

    Also I don't know how I handle adding a new record (adding a new day to the trip) cos it won't have an ID until it's patched to the SP List eh?

    This is my code to create a new record in the collection:

    Patch(
     colDetails,
     Defaults(colDetails),
     {
     ID: Value(TextInput2_32.Text),
     tripid: Value(TextInput2_26.Text),
     tripdate: DateValue(DatePicker1_1.SelectedDate),
     destination: TextInput2_25.Text,
     activity: TextInput2_27.Text,
     localcontact: TextInput2_28.Text,
     accomodation: TextInput2_29.Text,
     callintimes: TextInput2_30.Text,
     hoursworked: TextInput2_31.Text
     }
    );

     I really appreciate your assistance!

  • WarrenBelz Profile Picture
    WarrenBelz 143,591 on at
    Re: Having trouble updating rows in a gallery

    @bobgodin ,

    Then you would do this - collection Patch

    Patch(
     colDetails,
     Defaults(colDetails),
     {
     listid: Value(TextInput2_32.Text),
     tripid: Value(TextInput2_26.Text),
     tripdate: Gallery6_4.Selected.tripdate,
     destination: TextInput2_25.Text,
     activity: TextInput2_27.Text,
     localcontact: TextInput2_28.Text,
     accomodation: TextInput2_29.Text,
     callintimes: TextInput2_30.Text,
     hoursworked: TextInput2_31.Text
     }
    );

    List Patch

    Patch(
     TripDetails,
     ForAll(
     colDetails As aPatch,
     {
     ID: aPatch.listid,
     tripid: aPatch.tripid,
     tripdate: aPatch.tripdate,
     destination: aPatch.destination,
     activity: aPatch.activity,
     accomodation: aPatch.accomodation,
     localcontact: aPatch.localcontact,
     callintimes: aPatch.callintimes,
     hoursworked: aPatch.hoursworked
     }
     )
    );

     

    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

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard