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

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

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

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!

Top Solution Authors
Users online (45,887)