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 / edit entry in gallery ...
Power Apps
Unanswered

edit entry in gallery creates new entry

(0) ShareShare
ReportReport
Posted on by 407

Hi, have an app where if user goes in to ammend an entry, it instead creates an additional entry.

First screen, user populates fields and onselect of save button is set to,

Collect(KBLCollection, {Date:DatePicker2.SelectedDate,Customer:Customer_ED.Selected.Value});
SaveData(KBLCollection, “KBLCollectKeep”)

 

Then navigates to a gallery (CollectGallery) where the user can select the arrow (which navigates to a second screen with textinput fields set to the gallery. e.g. CollectGallery.Selected.Customer. here they can edit the entry. On this screen i have an update record button with the onselect set to,

 

Patch(KBLCollection,CollectGallery.Selected,{Date:Date_2.SelectedDate,Customer:Customer_2.Selected.Value}); SaveData(KBLCollection, "KBLCollectKeep");

 

Problem i am having is when you amend the entry and select the update record button, rather then updating the existing entry, it creates a new one in the gallery.
Any ideas?

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at

    Hi @Matt383 ,

    On the first one is collecting and then saving for (I assume) some offline use.

    Collect(
     KBLCollection, 
     {
     Date:DatePicker2.SelectedDate,
     Customer:Customer_ED.Selected.Value
     }
    );
    SaveData(KBLCollection, “KBLCollectKeep”)

    I assume you now want to amend this item and patch the amendment back and the save icon/button is outside the gallery?

    Patch(
     KBLCollection,
     CollectGallery.Selected,
     {
     Date:Date_2.SelectedDate,
     Customer:Customer_2.Selected.Value
     }
    ); 
    SaveData(KBLCollection, "KBLCollectKeep");

    If you put the save icon inside the gallery beside the item, you can do this

    Patch(
     KBLCollection,
     ThisItem,
     {
     Date:Date_2.SelectedDate,
     Customer:Customer_2.Selected.Value
     }
    ); 
    SaveData(KBLCollection, "KBLCollectKeep");

    I also assume here that Date_2 and Customer_2 are inside the gallery.

     

    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.

     

     

     

  • Matt383 Profile Picture
    407 on at

    Hi Warren, yes the app is used mostly offline. 

    This is the first screen, all text inputs

    Matt383_0-1618886920671.png

    Once they select the tick  (Collect(KBLCollection....), user is navigated to another screen with the gallery

    Matt383_1-1618887213433.png

    Now if user wants to edit the entry in the gallery, they click on the arrow, which then navigates them to another screen with all text inputs set to e.g. CollectGallery.Selected.Company, 

    Matt383_2-1618887540386.png

    When the user clicks save on this screen (Patch(KBLCollection...) and go back into the gallery the exitsting entry has no changes and there is now a new entry with all changes. I dont really have enough room in the gallery for a save button. Is there something missing in the patch?

    Date_2 and Customer_2 are the name of textinput fields in the edit screen, last image. 

    In the first screen, the text input fields are DatePicker2 and Customer_ED

     

  • WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at

    @Matt383 ,

    I have seen this issue a couple of times recently where Gallery.Selected does not identify the record you need to Patch, hence it writes a new record. If you have a unique identifier in the data (for example the collection comes from a SharePoint List), you can use {ID:GalleryName.Selected.ID} and it finds the right record. You can also do what I suggested and use ThisItem from within the gallery as that also works.

    Firstly, Date is a very bad title for a field as it is a Reserved Word in Power Apps, but putting this aside, if this is a unique record you could try

    Patch(
     KBLCollection,
     Lookup(
     KBLCollection,
     Text(Date,ShortDate) = Text(DatePicker2.SelectedDate,ShortDate) &&
     Customer=Customer_ED.Selected.Value
     ),
     {
     Date:Date_2.SelectedDate,
     Customer:Customer_2.Selected.Value
     }
    ); 
    SaveData(KBLCollection, "KBLCollectKeep");

     

    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.

     

     

  • Matt383 Profile Picture
    407 on at

     

    Hi Warren, the patch lookup diddnt seem to work, no error just diddnt save any changes in the gallery

     

    i dont have a unique identifier from sharepoint list but am using an ID
    Collect(KBLCollection, {Submitted:false, UserID:UniqueuserID_Input.Text,Title:Employee_ED.Selected.Value,Date:DatePicker2.SelectedDate,Customer:Customer_ED.Selected.Value});
    SaveData(KBLCollection, "KBLCollectKeep");
    Reset(UniqueuserID_Input);Reset(Employee_ED);Reset(DatePicker2);Reset(Customer_ED);Reset(CollectGallery);
    Navigate(ED_Collection)

     

    Patch(KBLCollection,CollectGallery.Selected,{UserID:TextInput4.Text,Customer:Customer_2.Selected.Value,Date:Date_2.SelectedDate,Title:Employee_2.Selected.Value});
    SaveData(KBLCollection, "KBLCollectKeep");
    Reset(TextInput4);Reset(Customer_2);Reset(Date_2);Reset(Employee_2);
    Navigate(ED_Collection)

    Still same issue as before. Really cant put save button in gallery, is setup as mobile app and already getting quite busy in there. 

  • WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at

    Hi @Matt383 ,

    As I mentioned your issue is that Power Apps is not picking up the record it has to Patch form Gallery.Selected. You need to supply the unique identifier - I would suggest this - first part

    Collect(
     KBLCollection, 
     {
     Submitted:false, 
    	 UserID:UniqueuserID_Input.Text,
    	 Title:Employee_ED.Selected.Value,
    	 Date:DatePicker2.SelectedDate,
    	 Customer:Customer_ED.Selected.Value
     }
    );
    SaveData(KBLCollection, "KBLCollectKeep");
    Reset(Employee_ED);
    Reset(DatePicker2);
    Reset(Customer_ED);
    Reset(CollectGallery);
    Navigate(ED_Collection)

    Note that I have not reset UniqueuserID_Input.

    Next part

    Patch(
     KBLCollection,
     {UserID:UniqueuserID_Input.Text},
     {
     UserID:TextInput4.Text,
     Customer:Customer_2.Selected.Value,
     Date:Date_2.SelectedDate,
     Title:Employee_2.Selected.Value
     }
    );
    SaveData(KBLCollection, "KBLCollectKeep");
    Reset(TextInput4);
    Reset(UniqueuserID_Input);
    Reset(Customer_2);
    Reset(Date_2);
    Reset(Employee_2);
    Navigate(ED_Collection)

     

    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.

     

  • WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at

    Hi @Matt383 ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

    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.

  • Matt383 Profile Picture
    407 on at

    Hi Warren,

     

    apologies for the late reply. I tried the above solution, which appeared to work, however when i went to edit a 2nd record or the same one, it created a new entry as before. I have another app with the uniqueID set on a dropdown field called (Employee_ED) with the Onchange set to Set(uniqueIDuser1,"N"&Text(Now(),"[$-en-US]yymmddhhmmss")) and it works without any issues. I have tried to replicate this but still have the same issues 😕

  • WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at

    @Matt383 ,

    This is a logic exercise, not a coding one (your code is valid). Have a think about what happens with UniqueUserID - put a label on the screen with this value and see if it is what you expect during the process.

     

  • Matt383 Profile Picture
    407 on at

    Yes I put a label to see what's happening, Once entry created ID created e.g 244. When i go into edit the entry label linked to ID (CollectGallery.Selected.UserID) is still 244 and edit is successful. Once edited, if i go back in there to edit again, ID has now changed to 233, thus creating new entry. 

  • WarrenBelz Profile Picture
    154,496 Most Valuable Professional on at

    OK @Matt383 ,

    I cannot see your model, so only trying to guide here - how and when is UniqueUserID set?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 531 Most Valuable Professional

#2
Haque Profile Picture

Haque 261

#3
Kalathiya Profile Picture

Kalathiya 221 Super User 2026 Season 1

Last 30 days Overall leaderboard