web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Power Fx Command Bar -...
Power Apps
Answered

Power Fx Command Bar - Cloning a child record and relating the clone to the parent

(0) ShareShare
ReportReport
Posted on by 401

Hello!

There are a few blog posts that show for Power Fx can be used in the command bar editor (preview) to create a new record. Using the Patch function with Self.Selected.Item, it is easy enough to create a copy of a record. However, I can't seem to get the Patch function to update the value of a lookup field. 

 

To be more precise: the record I am trying to copy is a child record, in a N:1 relationship with a parent record. The child record is shown in a subgrid on a form for the parent record. As such, the child record has a lookup column that relates it to the parent record. I can easily use the Patch function with a custom button on the subgrid to create a copy of the child record... for every field except that lookup field. 

 

Here is an excerpt of the the formula I am using (all tables are custom tables, no Dynamics in this environment). For simplicity's sake, I have included only two columns, a text column and a lookup column. In my scenario, Many Quotes relate to One RFQ. Quote # is a text column (primary name), and 'RFQ ID' is a Lookup column.

Patch(Quotes, Defaults(Quotes),{'Quote #':Self.Selected.Item.Autonumber & Self.Selected.Item.QuoteVersion + 1, 'RFQ ID':Self.Selected.Item.'RFQ ID'})

 

The button shows up as it should:

CharlesS_0-1637635270450.png

 

The form of the original record (the one I tried to copy) shows the relationship to the parent record, Test Project (this is why it shows up on the subgrid):

CharlesS_1-1637635495566.png

 

When I click on the subgrid command button, it does indeed create a new record, assigning the proper name. However, it does not relate it to the parent record (therefore does not show up on the subgrid in the parent record's form):

CharlesS_2-1637635621797.png

 

I also tried to use the Relate() function, but I can't seem to get that to work either. Any ideas? Thanks!

Categories:
I have the same question (0)
  • Verified answer
    PHalseyKMS Profile Picture
    20 on at

    I know it's been a while since you posted this question but I thought I would reply as I just hit the same issue and found a work around/solution.

     

    I noticed that in the Self.Selected.Item object all the lookup attributes aren't load correctly and so can't be used during the patch. 

    The solution I found was to use the With and LookUp commands to get the full copy of the record you are cloning and then use this in the Patch.  Below is a quick example of how you would lay it out.

    With(
    {
    recordToClone: LookUp(datasource, Key = Self.Selected.Item.Key)
    },
    Patch(
    datasource,
    Defaults(datasource),
    {
    Parent: recordToClone.Parent
    }
    )
    );

     

    Phil

    KMS Software

    www.kms-software.com 

  • cwebb365 Profile Picture
    3,294 Most Valuable Professional on at

    Noticed this myself and figured it out, used to have weird binding issues with datasources on old apps before so found it quickly. Kind of annoying. Great share. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard