I would like to patch the record into Dataverse tables, table "Samples" and table "Sample Products". I was able to patch the "Samples" master table record through the Patch function in PowerApps but when I patch "Sample Products" which is the detail table, it throws an error message "Value must be a data entity record" in PowerApps. I added screenshots of the code please review and let me know the best way to patch both tables through PowerApps.
Patch code for "Samples" master table:
Patch(
Samples,
Defaults(Samples),
{
Requester: DC_Requester.Text, //DataType:Text, Type:Custom, Optional
'Purpose of Sample': DC_PurposeOfSample.Selected.Value, //DataType:Choice, Type:Custom, Optional
'Sample Recipient': DC_SampleRecipient.Text, //DataType:Text, Type:Custom, Optional
Contact: DC_Contract.Selected, //DataType:Lookup, Type:Custom, Optional
'Requested Arrival Date': DV_RequestedArrivalDate.SelectedDate, //DataType:Date Only, Type:Custom, Optional
'Additional Inclusions ': DC_AdditionalInslusions.Selected.Value, //DataType:Choice, Type:Custom, Optional
'Additional Inclusions Details': DC_AdditionalInclusionsDetails.Text, //DataType:Text, Type:Custom, Optional
'Other Considerations': DC_OtherConsiderations.Text, //DataType:Text, Type:Custom, Optional
'Address Line 1': DC_AddressLine1.Text, //DataType:Text, Type:Custom, Optional
'Address Line 2': DC_AddressLine2.Text, //DataType:Text, Type:Custom, Optional
City: DC_City.Text, //DataType:Text, Type:Custom, Optional
'State/Province': DC_StateProvince.Text, //DataType:Text, Type:Custom, Optional
'Zip/Postal Code': DC_ZipPostalCode.Text, //DataType:Text, Type:Custom, Optional
Country: DC_Country, //DataType:Choice, Type:Custom, Optional
'Sample Title': DC_SampleTitle.Text, //(Primary Name Column), DataType:Text, Type:Custom, Required
'Status Reason': 'Status Reason (Samples)'.Draft, //DataType:Choice, Type:Standard, Optional
Owner: LookUp(
Teams,
name = "Sample Coordinator"
) //DataType:Owner, Type:Standard, Required
}
)
//Field:Sample, DataType:UniqueIdentifier, Type:Standard, Required
Patch code for "Sample Products" detail table
ForAll(
GallerySelectedProducts.AllItems,
Patch(
'Sample Products',
Defaults('Sample Products'),
{
Item: Txt_Item, //DataType:Lookup, Type:Custom, Optional
UOM: Txt_Unit, //DataType:Lookup, Type:Custom, Optional
'Quantity ': Txt_Quantity, //DataType:Whole Number, Type:Custom, Optional
'Packaging Format ': Txt_Packaging, //DataType:Choice, Type:Custom, Optional
'Other Product Attributes': Txt_Other, //DataType:Text, Type:Custom, Optional
Owner: LookUp(
Teams,
name = "Sample Coordinator"
) //DataType:Owner, Type:Standard, Required
}
)
)
//Field:Sample, DataType:Lookeup, Type:Custom, Optional
//Field:Sample Products, DataType:Unique Identifier, Type:Standard, Requried
It would be highly appreciated if someone can help me sort out how should I patch two different tables in a single patch or if I have to patch one after another so how should I go about it. Also, should I need to use a Unique Identifiers field "Sample" in the "Sample" table as I mentioned at the bottom of the code's comments above?
It would be highly appreciated if you can show me some Master and Detail tables update through Patch Function.
Note: For clarification, "Sample" is a field name in the "Sample" table, so I am referring to "Sample" as a field name as well as a table name. I colour-coded "Sample" Orange when referring as field name and Blue when referring as table name just to avoid confusion. Again we have a master table named "Sample" and a detailed table named "Sample Products", and in the "Sample" table we have a field named "Sample" which is a unique identifier filed in the master table.
Thank you in anticipation
@muzammilhussain You can't Patch 2 Tables in one Patch statement. As you have many fields, the best way to find the error would be by commenting all the fields and then checking them one by one. Once we find the field where the error is, it'll be easy to fix it.
@CNT Thank you, good advice I'll check and update. So, we have to patch the Detail table "On Success" of the Master Form submit? or there are any other best practices to update Master and Detail? especially for Dataverse
@muzammilhussain If the Details table has a Lookup to the Master table (and if that value is required) you'll have to Patch the Master first as you will need the Lookup value.
Thank you @CNT ,
Yes, This app solution has a Lookup field named "Sample" in a detailed table named "Sample Products" and this lookup field is Optional in the detail table. However, this "Sample" filed is a Unique Identifier in a master table "Sample" and it is a Required field in the master table.
Note: For clarification, "Sample" is a field name in the "Sample" table, so I am referring to "Sample" as a field name as well as a table name 🙂 I colour-coded "Sample" Orange when referring as field name and Blue when referring as table name just to avoid confusion. Again we have a master table named "Sample" and a detailed table named "Sample Products", and in the "Sample" table we have a field named "Sample" which is a unique identifier filed in the master table.
So, when I run my patch for the master table "Sample" it patches the record successfully, although my Patch statement does not have a "Sample" field as it is autogenerating some special id i.e. "47f40410-4dc9-eb11-..." you can see the Patch(Samples, Defaults(Samples),{... in my post above.
The Challenge:
On the other hand, when I tried to patch the "Sample Products" table, I received an error as I know I am not adding a "Sample" lookup filed in my patch. So my challenge is, how I can define this "Sample" field in the detail table's patch function ForAll. I am using Collection/Gallery for multiple records as I mentioned patch codes in my post above. ForAll(
GallerySelectedProducts.AllItems,
Patch(
'Sample Products',
Defaults('Sample Products'),
{...
Thank you again in anticipation
@muzammilhussain You had mentioned that Sample is generated in the Sample table. So, if you want to patch the details table with this new Sample, instead of patching the Master table, first if you do a SublitForm(), the OnSuccess() will fire, if everything was OK. There you can get the Sample using the formula, self.LastSubmit.Sample. You can then use this to patch the details table.
@CNT Thank you! I tried the (Sample Product) detail table's patch code on the (Sample) master table's SubmitForm(), the OnSuccess(), using Self.LastSubmit.Sample but having the following GUID issue
@muzammilhussain What I understand is that the Sample field in the Sample Products table is expecting a record. So, that part of the formula will look like,
Sample: Self.LastSubmit
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
11 | |
8 | |
7 | |
6 | |
4 |
User | Count |
---|---|
38 | |
23 | |
12 | |
8 | |
8 |