
Announcements
I'm at my wits end and need some help figuring out why my patch function isn't working correctly.
I have multiple dataverse tables that I need to grab data from and post the results of my form to a master table.
To achieve this, I have a combo box to select a value from one of my data sources. Once that is selected, I want to also grab additional values from that row in the table to ultimately post the info to a master data table. So, one selection... post multiple results.
Patch(
DumpLoads_1,
Defaults(DumpLoads_1),
{
Dumpload_FieldNumber: ComboBox1.Selected.'Field Number', //patches correctly
Dumpload_Project: ComboBox1.Selected.Field_Project, //patches a blank even though there is data in that field
Dumpload_FarmerName: ComboBox1.Selected.Field_Farmer, //patches correctly
Dumpload_TruckNumber: ComboBox2.Selected.'Truck Number',
Dumpload_Tons: Label1_2.Text //patches correctly based on the lookup but is not practicle.
}
);
If(
// check if there are errors
!IsEmpty(Errors(DumpLoads_1)),
// if true, show any error message
Notify(
"Data submission failed",
NotificationType.Error
),
// else, go to success screen
Navigate('Success Screen');
)
The code works great for the primary text that is selected in the combobox ComboBox1.Selected.'Field Number', it also works for the secondary line of data shown in the combo box ComboBox1.Selected.Field_Farmer. However, any other value i want to grab like ComboBox1.Selected.Field_Project doesn't write back during the patch and also returns a "Blank" when just looking at the code in powerapps.
However, If i create a label using the lookup function LookUp(Field, Field_FieldNumberAsText = ComboBox1.Selected.'Field Number').Field_Project and then write the results of that lookup it works fine. But I am going to be grabbing 50 objects to write back to the master list and doing a lookup for that many labels is a terrible idea for performance and I'm sure not a best practice.
What am I missing here? Do i need to do a lookup in the patch function first so that the referenced table data has a reference? I know it is something simple but I can't figure it out.
Thanks for your help
Wow! Thanks so much! All 3 of these solutions worked in some form. I went the route that @Mudassar_SZ365 recommended as it gave the best result. I'm posting my code here to hopefully help the next person. Thanks everyone, I spent hours on this and you solved it in 2 minutes. Marking this a solved.
Set(
varSelectedItem,
LookUp(Field, 'Field Number' = ComboBox1.Selected.'Field Number')
);
Set(
varSelectedItem2,
LookUp(Truck, 'Truck Number' = ComboBox2.Selected.'Truck Number')
);
Patch(
DumpLoads_1,
Defaults(DumpLoads_1),
{
Dumpload_FieldNumber: varSelectedItem.'Field Number',
Dumpload_Project: varSelectedItem.Field_Project,
Dumpload_ActualMiles: varSelectedItem.Field_ActualMiles,
Dumpload_FarmerName: varSelectedItem.Field_Farmer,
Dumpload_TruckNumber: ComboBox2.Selected.'Truck Number',
Dumpload_Carrier: varSelectedItem2.Truck_Carrier,
Dumpload_Tons: varSelectedItem2.Truck_Tons
}
);
If(
// check if there were any errors when dumpload submitted
!IsEmpty(Errors(DumpLoads_1)),
// if true, show any error message
Notify(
"Dumpload submission failed",
NotificationType.Error
),
// else, go to success screen
Navigate('Success Screen');
)