cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
eddyg
Helper I
Helper I

Can't Patch CDS Lookup Field

I've had a look at this post "Patching a CDM Lookup Field" but I'm either getting confused or don't quite understand how to do this.

 

I have two Entities, and I've created a relationship on 'Construction Daily Report' that points to 'Construction Report Project'

  1. Entity - Construction Report Project
    1. Field - PrimaryId
    2. Field - ProjectCode
  2. Entity - Construction Daily Report
    1. Field - PrimaryId
    2. Lookup Field - ConstReportProject_ (The way I understand it, this is actually the whole record)

I don't want the user to update the Lookup Field - ConstReportProject_ using the dropdown. I want to do it as a Patch once the record is saved using the Form OnSuccess to achieve this. I have a Context Variable (ProjectId) that is set as the PrimaryId of the Entity - Construction Report Project and I want to use that to Patch the lookup field in Entity - Construction Daily Report.

 

When I write the formula, everything goes well until I get to the the part were I'm supposed to enter the field to update which in this case is the lookup field ConstReportProject_.

 

This is what my formula looks like so far:

 

Patch('Construction Daily Report',First(Filter('Construction Daily Report',PrimaryId = ReportEditForm.LastSubmit.PrimaryId)),

 

That is as far as I get and no suggestions come up after that to complete the formula. I thought the formula would look something like this but it doesn't work:

 

Patch('Construction Daily Report',First(Filter('Construction Daily Report',PrimaryId = ReportEditForm.LastSubmit.PrimaryId)), {ConstReportProject_:ProjectId})

 

 

Where am I going wrong?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @eddyg,

 

The workable patch formula for the lookup field in CDS should be:

Patch(Testing3,
         Defaults(Testing3),
         {Testing_:
                 {PrimaryId:"000001",Text:"Testing"}
            }
)

Here Testing3 is the entity that we use patch with, which contains a lookup field Testing_, to patch new value in the Testing_ field, the format should be: Lookup : {}

Things need to be noticed:

1. If there are fields defined as Primary key in the entity, and those fields are not managed by the system, then those fields must be included in the Patch parameter Updates record,

2. For lookup field, the corresponding elements could be found under the corresponding datacard field:

51.PNG

we could click the dropdown to check the all involved elements, another way to find those elements is through the lookup entity Field groups->Default Lookup, all the needed elements could be edited through the Defualt Lookup:

52.PNG

3. For the Lookup Field elements value, they must match to one record added in the Lookup entity (here should be Testing entity), with value and Data type.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-micsh-msft
Community Support
Community Support

Hi @eddyg,

 

Lookup field in PowerApps should be in record format, and the lookup elements value showed under the Lookup field should all be involved in the record, I will update here with the code examples.

 

Thanks for the patience.

Regards,

Michael

 

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @eddyg,

 

The workable patch formula for the lookup field in CDS should be:

Patch(Testing3,
         Defaults(Testing3),
         {Testing_:
                 {PrimaryId:"000001",Text:"Testing"}
            }
)

Here Testing3 is the entity that we use patch with, which contains a lookup field Testing_, to patch new value in the Testing_ field, the format should be: Lookup : {}

Things need to be noticed:

1. If there are fields defined as Primary key in the entity, and those fields are not managed by the system, then those fields must be included in the Patch parameter Updates record,

2. For lookup field, the corresponding elements could be found under the corresponding datacard field:

51.PNG

we could click the dropdown to check the all involved elements, another way to find those elements is through the lookup entity Field groups->Default Lookup, all the needed elements could be edited through the Defualt Lookup:

52.PNG

3. For the Lookup Field elements value, they must match to one record added in the Lookup entity (here should be Testing entity), with value and Data type.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Where do we see this information now? I have a complex control and need to see the fields to use for the Lookup in my Patch function. 

The data menu has changed since this post.  

Hi,
I am facing exactly the same problem in updating the lookup field value. Your solution seems very logical since system expects RECORD for related field but as the screens has been changed can you mention where can we find the corresponding elements of lookup field?
Thank you

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (22,984)