cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
panterra
Advocate III
Advocate III

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
Advocate III
Advocate III

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
Advocate III
Advocate III

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
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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

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

Top Solution Authors
Top Kudoed Authors
Users online (66,462)