cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
spsolutionsgrp
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
v-siky-msft
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
Drrickryp
Super User
Super User

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.  

v-siky-msft
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

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

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,051)