Hi all,
I can't seem to Patch more than two data sources in a single button on select. Is it becuase of my If function?
I've tried writting it a few times in different ways, but each time it only ever patches to my first two data sources. Such as using only one If statement and putting all three true patch values in there, but again, no luck.
If(
Or(
DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
),
Patch(
IERMasterDocuments,
Defaults(IERMasterDocuments),
{
PartNumber: GeneratedPN.Text,
CreatedOn: CreatedOn1.Text,
CreatedBy: CreatedBy1.Text,
DocumentType: DocumentTypeSelector.Selected.Result,
System: SystemTypePrefix.Text,
Project: ProjectTypeSelector.Selected.Result,
ProjectUniqueNumber: ProjectUnique2.Text,
Release: IssueInput.Text,
'Status (crec2_status)': StatusInput.Text,
Description: DescriptionInput.Text,
Notes: NotesInput.Text,
Barcode: GeneratedPN.Text,
Location: LocationInput.Text,
StockLevel: Value(QuantityInput.Text),
Cost: Value(CostInput.Text),
VendorCost: Value(VendorCostEachInput.Text)
}
);,
false
);
If(
Or(
DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
),
Patch(
IERStockHistories,
Defaults(IERStockHistories),
{
Title:"New Stock",
PartNumber:GeneratedPN.Text,
Quantity:Value(QuantityInput.Text),
CostEach:Value(CostInput.Text),
CostTotal:Value(CostInput*QuantityInput.Text),
EffectiveCost:Value(CostInput*QuantityInput.Text),
TakenBy:User().FullName,
Date:Text(Now(),"dd-mmm-yy"),
Reason:"Restocked"
}
);,
false
);
If(
Or(
DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
),
Patch(
IERPartsVendors,
Defaults(IERPartsVendors),
{
PartNumber: GeneratedPN.Text,
Vendor: VendorPicker.Selected.Result,
VendorPN: VendorPNInput.Text,
VendorDescription: VendorDesInput.Text,
VendorCost: Value(VendorCostInput.Text),
VendorQty: Value(VendorQtyInput.Text),
VendorCostEach: Value(VendorCostEachInput.Text)
}
);,
false
);
If(
Or(
DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
),
false,
Patch(
IERMasterDocuments,
Defaults(IERMasterDocuments),
{
PartNumber: GeneratedPN.Text,
CreatedOn: CreatedOn1.Text,
CreatedBy: CreatedBy1.Text,
DocumentType: DocumentTypeSelector.Selected.Result,
System: SystemTypePrefix.Text,
Project: ProjectTypeSelector.Selected.Result,
ProjectUniqueNumber: ProjectUnique2.Text,
Release: IssueInput.Text,
'Status (crec2_status)': StatusInput.Text,
Description: DescriptionInput.Text,
Notes: NotesInput.Text,
Barcode: GeneratedPN.Text
}
);
);
Patch(
IERMasterHistories,
Defaults(IERMasterHistories),
{
PartNumber:GeneratedPN.Text,
Change:"Initial Creation",
ChangeBy:User().FullName,
ChangeOn:Text(Now(),"dd-mmm-yy")
}
);
Set(
varInfoMode,
"0"
);
Reset(DocumentTypeSelector);
Reset('01_SystemTypeSelector');
Reset('02_SystemTypeSelector');
Reset('05_SystemTypeSelector');
Reset('07_SystemTypeSelector');
Reset('04_SystemTypeSelector');
Reset('10_SystemTypeSelector');
Reset(ProjectTypeSelector);
Reset(DescriptionInput);
Reset(NotesInput);
Reset(CreatedOn1);
Reset(LocationInput);
Reset(QuantityInput);
Reset(CostInput);
Reset(VendorPicker);
Reset(VendorPNInput);
Reset(VendorDesInput);
Reset(VendorCostInput);
Reset(VendorQtyInput);
UpdateContext({Checkbox2Value: false});
Navigate(MainScreen)
Can some one please point out why I can't get this to work? I've been trying to figure out a solution for two days now!
Thanks,
Luke.
Use the Monitor function in Power Apps, then press the button, look at the log in Monitor to see what the issue is, I suspect the later patches are throwing errors but you're not seeing them.
Additionally I would recommend that you should also be implementing the IfError() function whenever you use patch, as you have no guarantee that the patch worked successfully, but then you are resetting controls and navigating away afterwards. We use IfError to notify the user (or do something else) if there was an error while patching.
Cheers,
Sancho
Hi @LukeAThomas. To confirm, the first two data sources (IERMasterDocuments, IERStockHistories) are patched OK but the rest (IERPartsVendors, IERMasterDocuments, IERMasterHistories) are not?
Are the commands after the Patch calls (control Resets, Navigate, etc) working OK?
One test to try would be to call the Patch statements without If blocks around them to identify if the Patch commands themselves are not working as expected.
Infact, I removed the If function altogether, and I can still only patch the first two data sources, so I guess the question is more, how do I patch more than two different data sources?
I've been searching and I can't seem to find the answer anywhere....
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional