I have a SharePoint list integrated with a PowerApp. In the OnSave of the SharePointIntegration I am trying to update and validate different forms based on a selected vale and a checkbox. I cannot seem to get everything right with my if statements. I have some datacards required but with the current statements, it is letting me click the save button with or without the required fields populated but it is not actually saving my item to the list. Any help is appreciated. Below is the code I currently have:
If (
Checkbox1.Value = true,
If(
BasicInfoForm.Mode = FormMode.New && BasicInfoForm.Valid,
Patch(
'Business Asset',
Defaults('Business Asset'),
BasicInfoForm.Updates,
ManualAddForm.Updates
),
Patch(
'Business Asset',
SharePointIntegration.Selected,
BasicInfoForm.Updates,
ManualAddForm.Updates
)),
ResetForm(BasicInfoForm);
RequestHide()
);
If(
DataCardValue5.Selected.Value = "Manual Add" && Checkbox1.Value = false,
If(
BasicInfoForm.Valid && ManualAddForm.Valid,
If(
BasicInfoForm.Mode = FormMode.New,
Patch(
'Business Asset',
Defaults('Business Asset'),
BasicInfoForm.Updates,
ManualAddForm.Updates
),
Patch(
'Business Asset',
SharePointIntegration.Selected,
BasicInfoForm.Updates,
ManualAddForm.Updates
)
);
Notify("Please fill the required fields")
);
ResetForm(BasicInfoForm);
ResetForm(ManualAddForm);
RequestHide();
);
If(
DataCardValue5.Selected.Value = "Cost Adjustment" && Checkbox1.Value = false,
If(
BasicInfoForm.Valid && CostAdjustmentForm.Valid,
If(
BasicInfoForm.Mode = FormMode.New,
Patch(
'Business Asset',
Defaults('Business Asset'),
BasicInfoForm.Updates,
CostAdjustmentForm.Updates
),
Patch(
'Business Asset',
SharePointIntegration.Selected,
BasicInfoForm.Updates,
CostAdjustmentForm.Updates
);
Notify("Please fill the required fields")
)
);
ResetForm(BasicInfoForm);
ResetForm(CostAdjustmentForm);
RequestHide();
);
If(
DataCardValue5.Selected.Value = "Transfer" && Checkbox1.Value = false,
If(
BasicInfoForm.Valid && TransferForm.Valid,
If(
BasicInfoForm.Mode = FormMode.New,
Patch(
'Business Asset',
Defaults('Business Asset'),
BasicInfoForm.Updates,
TransferForm.Updates
),
Patch(
'Business Asset',
SharePointIntegration.Selected,
BasicInfoForm.Updates,
TransferForm.Updates
);
Notify("Please fill the required fields")
)
);
ResetForm(BasicInfoForm);
ResetForm(TransferForm);
RequestHide();
);
If(
DataCardValue5.Selected.Value = "Disposal" && Checkbox1.Value = false,
If(
BasicInfoForm.Valid,
If(
BasicInfoForm.Mode = FormMode.New,
Patch(
'Business Asset',
Defaults('Business Asset'),
BasicInfoForm.Updates
),
Patch(
'Business Asset',
SharePointIntegration.Selected,
BasicInfoForm.Updates
);
Notify("Please fill the required fields")
)
);
ResetForm(BasicInfoForm);
RequestHide();
);
If(
DataCardValue5.Selected.Value = "Adjust Useful Life / Accelerate Depreciation" && Checkbox1.Value = false,
If(
BasicInfoForm.Valid,
If(
BasicInfoForm.Mode = FormMode.New,
Patch(
'Business Asset',
Defaults('Business Asset'),
BasicInfoForm.Updates
),
Patch(
'Business Asset',
SharePointIntegration.Selected,
BasicInfoForm.Updates
);
Notify("Please fill the required fields")
)
);
ResetForm(BasicInfoForm);
RequestHide();
)
Thank you so much @BCBuizer! It wasn't exactly correct. There are actually 5 options and there were a couple typos but you definitely got me going in the right direction.
Here is what ended up working:
Hi @HollieD ,
Since you seems to be using FormMode, you can replace all of the patch functions to simplify your formula. Also by combining conditions in a single If statement further simplification can be achieved.
Applying these two, I can to the below formula:
If(
(Checkbox1 && BasicInfoForm.Valid)
(Checkbox1.Value = true && BasicInfoForm.Valid) ||
(DataCardValue5.Selected.Value = "Disposal" && Checkbox1.Value = false && BasicInfoForm.Valid) ||
(DataCardValue5.Selected.Value = "Adjust Useful Life / Accelerate Depreciation" && Checkbox1.Value = false && BasicInfoForm.Valid),
SubmitForm(BasicForm);
ResetForm(BasicInfoForm);
RequestHide(),
(DataCardValue5.Selected.Value = "Manual Add" && Checkbox1.Value = false || BasicInfoForm.Valid && ManualAddForm.Valid) ||
(DataCardValue5.Selected.Value = "Cost Adjustment" && Checkbox1.Value = false && BasicInfoForm.Valid && ManualAddForm.Valid) ||
(DataCardValue5.Selected.Value = "Transfer" && Checkbox1.Value = false && BasicInfoForm.Valid && ManualAddForm.Valid)
SubmitForm(BasicForm);
SubmitForm(ManualAddForm);
ResetForm(BasicInfoForm);
ResetForm(ManualAddForm);
RequestHide(),
Notify("Please fill the required fields")
)
Basically there are 3 options:
1. Only BasicForm is submitted
2. Both BasicForm and ManuallAddForm are submitted
3. A notification is given that required fields are missing.
The first two options have their own set of conditions, whereas the third is selected if none of the conditions for the first two options are met.