cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
panterra
Level 8

Patching a Lookup column in CDS 2.0 from PowerApps

Hi, 

 

Has anyone been able to Patch a new entry into a CDS 2.0 entity that includes a Lookup / relationship column? When I attempt to set the value of the lookup field in my Patch call, I get the following error: 

 

The type of this argument Company does not match the expected type 'DataEntity'. Found Type 'Text'

 

 

 
Patch(
    'Contract',
    Defaults('Milestones'),
    {
        'Contract Name':contractName.Text,
        'Start Date':dtContractStart.SelectedDate,
        'End Date':dtContractEnd.SelectedDate,
        'Status':cboStatus.Selected.Value,
        Responsible: cboContractOwner.Selected.Id,
        'Company':thisCustomer.conmpanyid
    }
)

 

I would like to see an example of how a Patch() call from within PowerApps can be used to set the value of a Lookup / Relationship field.

 

Thank you! 

Sean

1 ACCEPTED SOLUTION

Accepted Solutions
panterra
Level 8

Re: Patching a Lookup column in CDS 2.0 from PowerApps

Here's what I ended up getting to work: 

 

The Patch() call must be made to the Lookup columns internal column name (make sure the casing is correct. The value that is expected is a reference to the complete parent record.  

 

I was trying to pass in a reference to the ID of the company, where we need to provide the actualy company record. I am storing it in the variable thisCompany.  The error also changed (I logged out of PowerApps and returned), perhaps also refreshed the data connections. It was no longer looking for a DataEntity. It was looking for a Record.

 

NOTE: I've also found that if you add a Form to your UI and submit a record into the CDS entity using the form, that the DataEntity error no longer appears and a record data type is expected.

 

Patch(
    'Contract',
    Defaults('Contracts'),
    {
        'Contract Name':contractName.Text,
        'Start Date':dtContractStart.SelectedDate,
        'End Date':dtContractEnd.SelectedDate,
        'Status':cboStatus.Selected.Value,
        Responsible: cboContractOwner.Selected.Id,
        'Company':thisCompany
    }
)

 

 

View solution in original post

1 REPLY 1
panterra
Level 8

Re: Patching a Lookup column in CDS 2.0 from PowerApps

Here's what I ended up getting to work: 

 

The Patch() call must be made to the Lookup columns internal column name (make sure the casing is correct. The value that is expected is a reference to the complete parent record.  

 

I was trying to pass in a reference to the ID of the company, where we need to provide the actualy company record. I am storing it in the variable thisCompany.  The error also changed (I logged out of PowerApps and returned), perhaps also refreshed the data connections. It was no longer looking for a DataEntity. It was looking for a Record.

 

NOTE: I've also found that if you add a Form to your UI and submit a record into the CDS entity using the form, that the DataEntity error no longer appears and a record data type is expected.

 

Patch(
    'Contract',
    Defaults('Contracts'),
    {
        'Contract Name':contractName.Text,
        'Start Date':dtContractStart.SelectedDate,
        'End Date':dtContractEnd.SelectedDate,
        'Status':cboStatus.Selected.Value,
        Responsible: cboContractOwner.Selected.Id,
        'Company':thisCompany
    }
)

 

 

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,451)