cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Issue with Patch back to Lookup in CDS

I am running into errors and issues when trying to patch two different entities with a lookup field.  The included screenshots will show most of the story but I will also try to explain.

 

CDS entities

PURCHASE ORDERS

Name [Text]

PO Number [Whole Number]

Vendor [lookup]

 

ORDER DETAILS

PO Item Number [AutoNumber]

PO Number [lookup] (to the PO Number field on the PURCHSE ORDERS entity)

Quantity [Whole Number]

Stock Number [lookup]

 

Patch(
Orders,
Defaults(Orders),
{
Name: "Test3",
Vendor: dd_Vendor.SelectedText,
cr014_ponumber: Value(txt_PONumber.Text)
}
);

ForAll(POItemGallery.AllItems,
Patch(
'Order Details',
Defaults('Order Details'),
{
cr014_ponumber:lbl_POItemPONumber,
Quantity: Value(lbl_POItemQuantity.Text),
cr014_StockNumber: lbl_POItemStockNumber
}
))

 

 

I get an "value must be a data entity record" error.   I understand the error says it is looking for a record but I am not sure how to get it the correct data.

 

Thank you in advance for any help that you can provide.

 
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Issue with Patch back to Lookup in CDS

Hi @spsolutionsgrp ,

 

I think the issue you are facing is how to patch a lookup field into entity.

You can simply understand that the lookup field stores the related records in the parent entity, so try to use LookUp function to retrieve the related record based on the label value in cr014_ponumber and cr014_StockNumber part code. 

 

ForAll(POItemGallery.AllItems,
Patch(
'Order Details',
Defaults('Order Details'),
{
cr014_ponumber: LookUp('Purchase Orders', 'PO Number' =lbl_POItemPONumber)
Quantity: Value(lbl_POItemQuantity.Text),
cr014_StockNumber: LookUp( 'Stock Number Entity', 'Stock Number'=lbl_POItemStockNumber) // replace by the real entity name and column name
}
))

 

Hope this helps.

Sik

View solution in original post

3 REPLIES 3
Highlighted
Super User III
Super User III

Re: Issue with Patch back to Lookup in CDS

Hi @spsolutionsgrp 

Could you please clarify what you want to do with your patch. It looks like you are trying to do too much at one time.  Please look at the Northwind Sample database.  It can be downloaded from here. https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/northwind-install  If you go through the exercise, I believe you will find out how to design your app.  It seems very much on point.  

Highlighted
Community Support
Community Support

Re: Issue with Patch back to Lookup in CDS

Hi @spsolutionsgrp ,

 

I think the issue you are facing is how to patch a lookup field into entity.

You can simply understand that the lookup field stores the related records in the parent entity, so try to use LookUp function to retrieve the related record based on the label value in cr014_ponumber and cr014_StockNumber part code. 

 

ForAll(POItemGallery.AllItems,
Patch(
'Order Details',
Defaults('Order Details'),
{
cr014_ponumber: LookUp('Purchase Orders', 'PO Number' =lbl_POItemPONumber)
Quantity: Value(lbl_POItemQuantity.Text),
cr014_StockNumber: LookUp( 'Stock Number Entity', 'Stock Number'=lbl_POItemStockNumber) // replace by the real entity name and column name
}
))

 

Hope this helps.

Sik

View solution in original post

Highlighted
Helper V
Helper V

Re: Issue with Patch back to Lookup in CDS

Thank you,  I tried Filter but forgot about the Lookup function.  Thanks

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (7,915)