web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Need help with If stat...
Power Apps
Answered

Need help with If statement on the OnSave event

(0) ShareShare
ReportReport
Posted on by 7

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();

)

Categories:
I have the same question (0)
  • Verified answer
    BCBuizer Profile Picture
    22,654 Super User 2026 Season 1 on at

    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. 

  • HollieD Profile Picture
    7 on at

    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.

    1. Only BasicForm is submitted
    2. Both BasicForm and ManuallAddForm are submitted
    3. Both BasicForm and CostAdjustmentForm are submitted
    4. Both BasicForm and TransferForm are submitted
    5. A notification is given that required fields are missing.

    Here is what ended up working:

    If(
    (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(BasicInfoForm); 
    ResetForm(BasicInfoForm);
    RequestHide(),
     
    (DataCardValue5.Selected.Value = "Manual Add" && Checkbox1.Value = false && BasicInfoForm.Valid && ManualAddForm.Valid), 
     
    SubmitForm(BasicInfoForm);
    SubmitForm(ManualAddForm);
    ResetForm(BasicInfoForm);
    ResetForm(ManualAddForm);
    RequestHide(),
     
    (DataCardValue5.Selected.Value = "Cost Adjustment" && Checkbox1.Value = false && BasicInfoForm.Valid && CostAdjustmentForm.Valid), 
     
    SubmitForm(BasicInfoForm);
    SubmitForm(CostAdjustmentForm);
    ResetForm(BasicInfoForm);
    ResetForm(CostAdjustmentForm);
    RequestHide(),
     
    (DataCardValue5.Selected.Value = "Transfer" && Checkbox1.Value = false && BasicInfoForm.Valid && TransferForm.Valid),
     
    SubmitForm(BasicInfoForm);
    SubmitForm(TransferForm);
    ResetForm(BasicInfoForm);
    ResetForm(TransferForm);
    RequestHide(),
     
    Notify("Please fill the required fields")
    )
  • BCBuizer Profile Picture
    22,654 Super User 2026 Season 1 on at

    Hi @HollieD ,

     

    Glad to see you got this working 🙂 .

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 490

#2
WarrenBelz Profile Picture

WarrenBelz 427 Most Valuable Professional

#3
Vish WR Profile Picture

Vish WR 381

Last 30 days Overall leaderboard