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 / Gallery - want to crea...
Power Apps
Answered

Gallery - want to create a duplicate record

(0) ShareShare
ReportReport
Posted on by 6

Hello,

 

I have a gallery that displays information that is from a collection. A user can indicate if they want to create a similar record from the gallery. I want all of the fields and information to be maintained, but to have the opportunity to change only the ID# as well as an indication to note that this is now a duplicate/similar record. I found a similar thread: https://powerusers.microsoft.com/t5/Building-Power-Apps/Create-a-second-record-entry-from-gallery/td-p/74611 but something is different and I don't think the original poster was using a collection to power the gallery to start. When I've attempted to re-create, I end up with either multiple collections, identical ID#'s, or completely blank information. Could anyone break down the rules of the code for me and how to apply the same principle to a collection?

 

Much appreciated.

Categories:
  • GarethPrisk Profile Picture
    2,828 on at
    Your collection has an ID column, correct?
    What data type is it?
    How is it being set now? Can we simply increment?
    This is a straight-forward solution, just want to understand your ID field. Also, if would be helpful to see the function used to generate the collection/collect an item into the collection for reference.
  • WarrenBelz Profile Picture
    156,545 Most Valuable Professional on at

    Hello @boedern ,

    I can give you a simple process which would (from inside the gallery) add a copy of the current item to the data source. I will call the list TestList

    ClearCollect(colTest,ThisItem);
    Collect(TestList,colTest)

    From outside the gallery (again for the current selected item (gallery name is GalleryTest)

    ClearCollect(colTest,GalleryTest.Selected);
    Collect(TestList,colTest)

    This works as Collect can be used to add new records as long as the field names are the same as those from the collection

    You could also Patch back the collection, but this approach is simpler.

     

    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.

  • Verified answer
    GarethPrisk Profile Picture
    2,828 on at

    @WarrenBelzI would use a similar approach. However, I think that @boedern is looking to also increment an ID field to not create an exact duplicate of the record, but instead clone the record as a new unique record.

    This requires a relatively basic UpdateIf pattern to what you suggested.

    For my example, I'll build a collection

    ClearCollect(
     colMain,
     {
     mainID: 1,
     mainName: "Record 1",
     mainDate: Today()
     },
     {
     mainID: 2,
     mainName: "Record 2",
     mainDate: Today()
     }
    )

    Then I'll add a Gallery and use colMain as the Items property. I mapped the fields, then added another control to trigger the clone. For the OnSelect of that control, I added the following function.

    Select(Parent);
    // Collect the Item into a temporary collection
    ClearCollect(
     colClone,
     ThisItem
    );
    // Update the necesssary properties of the Clone
    UpdateIf(
     colClone,
     mainID = mainID,// Identifer column, but any column will work
     {
     mainName: Concatenate(
     mainName,
     " (Clone)"// Appends the (Clone) text for easy identification
     ),
     mainID: Max(
     colMain,
     mainID
     ) + 1// Increments the Max ID from colMain by 1
     }
    );
    // Collect the Cloned item into Main
    Collect(colMain,colClone);
    // Cleanup isn't necessary, since we begin with a ClearCollect

    Since my colMain's ID column is a number, I can simply increment it by 1 to get a new incremental number. This is why I was asking initially about your ID column, to understand how we could make/generate a unique ID. If it's not a number, we may need to change that part of the function, but the rest of the cloning operation will work.

  • boedern Profile Picture
    6 on at

    Thanks!

     

    This has mostly worked with the exception of the ID#. My sample ID number is Alphanumeric with the last 3 digits being generated through the RAND function. Since it is random, I'm a little hesitant to use the +1 just on the off chance it creates a duplicate ID. Also, as the line items are in a way linked (as they are copies) I was hoping to use an A,B,C... indicator on the end of the original ID#.

     

    What is currently happening though is that it replaces the ID# with a 1,2,3 rather than adding onto the end as well.

     

    Everything else worked perfectly! Thank you.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard