Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Query
Unanswered

Duplicate an associated record

(2) ShareShare
ReportReport
Posted on by 1,145
Good Morning,
 
I have a Model Driven App and have successfully duplicated a Contact record with the following 
 
ForAll(Self.Selected.AllItems,Patch(Contacts,Defaults(Contacts),{'First Name':ThisRecord.'First Name','Last Name':ThisRecord.'Last Name','Mobile Phone':ThisRecord.'Mobile Phone',Email:ThisRecord.Email}))
 
I want to be able to clone an associated record in a different set of tables. (nothing to do with Contact table)
 
Think a Quoting System against a product BUT the quote includes multiple pricing options based on Quantity for that single product.
 
I have a Quote Table that has a relationship with the Quote Line Item Table (that shows a Product), Inside the Quote Line Item Table there is a reference to the table Quote Line Item Calcs. This is the table where I want to Duplicate records.
 
In addition these multiple quantity options sit Innside an editable grid.
 
 
I don't want to use a flow as its too slow.
 
Is there a way to write a query that would duplicate just 1 quantity and user could then go back in and edit the quantity to what it might require?
 
Thanks
 
Todd
  • Tango Profile Picture
    Tango 1,145 on at
    Duplicate an associated record
    How do I reply to a response?
  • Robu1 Profile Picture
    Robu1 1,015 Super User 2025 Season 1 on at
    Duplicate an associated record
    Hi Todd,
    Thank you for choosing Mictosoft Community.
    You can achieve this by using a similar approach to your existing ForAll and Patch functions, but tailor it to your specific tables and relationships. 
    Here’s a step-by-step guide to help you clone a record in the Quote Line Item Calcs table:
    Identify the Record to Clone: First, identify the record in the Quote Line Item Calcs table that you want to duplicate.
    Use ForAll and Patch Functions: Use these functions to duplicate the record. You’ll need to adjust the fields and tables accordingly.
    Here’s an example of how you might write the query:
    ForAll(
        Self.Selected.AllItems,
        Patch(
            'Quote Line Item Calcs',
            Defaults('Quote Line Item Calcs'),
            {
                'Quote Line Item': ThisRecord.'Quote Line Item',
                'Quantity': ThisRecord.Quantity,
                'Price': ThisRecord.Price,
                'Total': ThisRecord.Total
            }
        )
    )
    In the example above:
    Self.Selected.AllItems refers to the items selected in your editable grid.
    Patch is used to create a new record in the Quote Line Item Calcs table.
    Defaults('Quote Line Item Calcs') initializes a new record.
    The fields inside the curly braces {} are the ones being duplicated from the selected record.
    Allow User to Edit Quantity: After duplicating the record, the user can go back and edit the Quantity field as needed.
    This approach avoids using a flow and should be faster. Make sure to adjust the field names and table names to match your actual schema.
    If you have any specific constraints or additional requirements, feel free to share them, and I can help refine the solution further!
     
     
    If this fixes the issue, please mark as resolved to help others with find it.
    Happy to help 
    Robu 1

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,318 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,111 Most Valuable Professional

Leaderboard

Featured topics