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.
The button shows up as it should:
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):
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):
I also tried to use the Relate() function, but I can't seem to get that to work either. Any ideas? Thanks!
Solved! Go to Solution.
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
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
User | Count |
---|---|
121 | |
87 | |
87 | |
75 | |
66 |
User | Count |
---|---|
215 | |
180 | |
138 | |
96 | |
82 |