Introduction
Power Apps screens frequently contain multiple forms for collecting various data sections. Repetitive code that becomes difficult to maintain over time can result from managing these forms individually, particularly when performing actions like reset, new, edit, view, Validate and Submit.
Using the ForAll() function to dynamically iterate over a collection of forms and apply actions is more effective and scalable. As the application expands, this approach improves maintainability, reduces duplication, and maintains clean code.
By combining ForAll() and ResetForm(), EditForm(), ViewForm(), and NewForm(), Validate and Submit, we will investigate how to effectively reset multiple forms with a single block of code in this article.
Traditional Approach (Repetitive Code)
//Reset Form
ResetForm(Form1);
ResetForm(Form2);
ResetForm(Form3);
//Edit Form
EditForm(Form1);
EditForm(Form2);
EditForm(Form3);
//New Form
NewForm(Form1);
NewForm(Form2);
NewForm(Form3);
//View Form
ViewForm(Form1);
ViewForm(Form2);
ViewForm(Form3);
//Validate and Submit Form
If(Form1.Valid&& Form2.Valid,Form3.Valid,
SubmitForm(Form1);
SubmitForm(Form2);
SubmitForm(Form3),
Notify("Form Not Valid"))
This method works, but as the number of forms grows, it gets longer and more difficult to manage.
Optimised Approach (Scalable Solution)
// Reset Form
ForAll(
[
Form1,
Form2,
Form3
] As frms,
ResetForm(frms.Value)
);
// New Form
ForAll(
[
Form1,
Form2,
Form3
] As frms,
NewForm(frms.Value)
);
//Edit Form
ForAll(
[
Form1,
Form2,
Form3
] As frms,
EditForm(frms.Value)
);
//View Form
ForAll(
[
Form1,
Form2,
Form3
] As frms,
ViewForm(frms.Value)
);
//Validate and Submit Form
ForAll(
[
Form1,
Form2,
Form3
] As frms,
If(
frms.Valid,
SubmitForm(Frm),
Notify("This From " & frms.Value& "Not Valid")
)
)
Conclusion
Power Apps can quickly make your code repetitive and difficult to maintain if you manage each form separately. Readability and scalability suffer as the number of forms increases by manually calling ResetForm() for each one.
You can perform actions like reset, new, edit, view, Validate and submit in a single, organised block of code by using the ForAll() function with a collection of forms.
This method makes your application easier to scale in the future, makes it easier to maintain, and cuts down on duplicate work. Better code organization and a more effective method for managing multiple forms within a screen are guaranteed by adopting this pattern.