cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Community Support
Community Support

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
Super User II
Super User II

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.  

Community Support
Community Support

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

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

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Users online (7,735)