Skip to main content

Notifications

Power Platform Community / Forums / Power Query / Duplicate an associate...
Power Query
Unanswered

Duplicate an associated record

Posted on by 1,133
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,133 on at
    Duplicate an associated record
    How do I reply to a response?
  • Robu1 Profile Picture
    Robu1 740 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

September 2024 Newsletter…

September 2024 Community Newsletter…

Community Update Sept 16…

Power Platform Community Update…

Tuesday Tip #2 Global Search…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 142,008

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,531

Leaderboard

Featured topics