10 Things You Should Know About Power Apps Forms

10 Things You Should Know About Power Apps Forms

Power Apps makes building data entry forms surprisingly simple – just insert a new form onto the screen, watch all of the fields in your data source magically appear in the form, then add a ‘submit’ button and you’re done. But forms also have many feature experienced makers must know to use them effectively. After you’ve learned to do the basics, what should you learn to do with forms next? I’ve created a top 10 list of the most useful and unexpected tips & tricks to help you become a master at building Power Apps forms.

Table Of Contents:
1.  Use One Form To Create, Edit & View Records (NewForm, EditForm, ViewForm Functions)
2.  Easily Perform Data Validation With One Line Of Code (Valid Property)
3.  Success Or Failure Message After A Form Is Submitted (OnSuccess/OnFailure Property)
4.  Get The Form's Last Submitted Record (Last Submit Property)
5.  Check If A Form Is Unsaved (Unsaved Property)
6.  Get A Single Record Showing All Form Updates (Updates Property)
7.  Style All Form Controls At Once (Tips & Tricks)
8.  Maintain X & Y Position When Copying Controls Inside A Form (Tips & Tricks)
9.  Create Multiple Page Forms On A Single Screen (Tips & Tricks)
10. Responsive Forms Change To Fit Screen Size (Tips & Tricks)




1. Use One Form To Create, Edit & View Records (NewForm, EditForm, ViewForm Functions)

New Power Apps makers often create two copies of the same form on separate screens: a fillable edit form for submitting data and another non-fillable form for viewing data. Making duplicate forms for creating, editing and viewing records is not necessary. Instead, you can use a single form and apply the NewForm, EditForm and ViewForm functions to change the Form Mode to what you currently need.



Here’s some sample code showing how to use each function. For a full tutorial about Form Modes check out this article.

// when form is submitted a new record is created
NewForm(Form1);

// when form is submitted, the current record is updated
EditForm(Form1);

// form cannot be submitted, input fields are view-only
ViewForm(Form1);




2. Easily Perform Data Validation With One Line Of Code (Valid Property)

Validating the data in a Power Apps form prior to submission is important. A form submission will be rejected when any field does not follow the rules in the data source. We can check if the form will pass data-validation with one-line of code like this. The Valid property will return a value of true for a pass and false for a fail.

Form1.Valid




When you know a form submission will fail you should prevent a users from submitting it in the first place. Use this code in the DisplayMode of a Submit button disable it when data validation fails.

If(Form1.Valid, DisplayMode.Edit, DisplayMode.Disabled)



For more advanced Power Apps data validation techniques check out this article.




3. Success Or Failure Message After A Form Is Submitted (OnSuccess/OnFailure Property)

After a Power Apps form is submitted you should tell the user whether the data was successfully saved. The wrong way to do it would be using this code in the OnSelect property of the form’s submit button because the form will always say it saved if even when it did not.

SubmitForm(Form1);
Notify(
    "Success: form was successfully saved",
    NotificationType.Success
);



Power Apps forms have a OnSuccess property that runs immediately following a successful save. Put the notification message there instead.

Notify(
    "Success: form was successfully saved",
    NotificationType.Success
);



There is also an OnFailure property that triggers after a failed save where you can write your failure notification message.

Notify(
    "Failed: form was not saved due to an error"
    NotificationType.Error
);





4. Get The Form’s Last Submitted Record (LastSubmit Property)

When a Power Apps form is successfully submitted a several fields not present in the app are automatically added to the record – ID, Created Date, Created By, Modified Date and Modified By. We can retrieve the updated record with these new values by using the form’s LastSubmit property.

Set(varRecordFormCurrent, Form1.LastSubmit);



Form1.LastSubmit looks like this:

{
    ID: 2
    Test Name: Mathematics,
    Student Name: Matthew Devaney,
    Score: 100,
    Created: Matthew Devaney
    Created By: 2021-11-16 5:23 PM
    Modified: Matthew Devaney
    Modified By: 2021-11-16 5:23 PM
}



The record found in this property is always the last submitted record for the current user’s session. Once the app is closed the LastSubmit property is cleared. It does not retrieve the last created/modified record for other users.




5. Check If A Form Is Unsaved (Unsaved Property)

When a user navigates away from a screen without saving a Power Apps form they should receive a warning to ensure there is no accidental data-loss. But how do we know if any fields on the form were updated with new values? Every form has an Unsaved property which evaluates to true when there unsaved changes and false when there are none.

Form1.Unsaved



We can use this code in the OnSelect property of a navigation button to check the the Unsaved property before going to the next screen.

If(
    Form1.Unsaved,
    Set(varBoolShowWarning, true)
    Navigate('Home Screen')
)



For more instructions on how to make pop-up menus in Power Apps check out this article.




6. Get A Single Record Showing All Form Updates (Updates Property)

As a user updates a Power Apps form a record is silently generated to track the changes. That record is what gets sent to the data source when we use the SubmitForm function. We can see the record by looking at the form’s Updates property.

Form1.Updates



The result will look something like this:

{
    Title: Bruno Mars
    Description: Superbowl Performance of a lifetime
    Date: 2021, 2, 14
}



The form record can be useful in these scenarios:

  • Using the Patch function to write data to the data source instead of SubmitForm
  • Calling a function from another connection than the data source
  • Storing the record in a collection data-type
  • Writing data to the local-device when in offline-mode




7. Style All Form Controls At Once Trick (Tips & Tricks)

Power Apps forms a huge time-saver because all of the input fields automatically appear and you don’t need to add them one-by-one. However, forms also have one big drawback: if you want to change the style of a form you must edit each control individually. There is no official way to perform mass-changes in studio-mode. Fortunately, this strange trick was discovered by Alan Chai to select all the form controls at once.

  1. Select the form
  2. Change the form layout from vertical to horizontal
  3. Click the undo button in the top right corner of Power Apps Studio
  4. All of the form’s controls will now be selected


For more awesome Power Apps tips and tricks check out this article.




8. Maintain X & Y Position When Copying Controls Inside A Form (Tips & Tricks)

Re-using a control you’ve already setup is a great way to save development time. But if you try copying it from one card in a form to another card the control moves to a random X & Y position. If you want to maintain the same X & Y properties multiply their value by 1 like this because Power Apps does not break formulas when copying a control

X: 30 * 1
Y: 10 * 1



This tip by Sancho Harker is so awesome I use it multiple times per day.




9. Create Multiple Page Forms On A Single Screen (Tips & Tricks)

Some forms are very long and have too many questions to fit on a screen. Fortunately, Power Apps forms can be split into multiple pages, dividing questions into smaller sections.



This is done by changing the visibility of each data card to show only when a variable storing the current screen matches page number

// show the data card only when on page 1 of the form
Visible: locCurrentPage = 1



For a full-tutorial on how to make multiple-page forms check out this article.




10. Responsive Forms Change To Fit Screen Size (Tips & Tricks)

Responsive app-design ensures a great user-experience whether user’s screen-size is large or small. A responsive-app changes its layout to best fit the display it is being viewed on. No extra work is needed to make a Power Apps form responsive – this feature is already included. Just insert a form inside your responsive-app and watch the fields become repositioned as you stretch and collapse the browser window.





Questions?

If you have any questions or feedback about 10 Things You Should Know About Power Apps Forms please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Matthew Devaney

Subscribe
Notify of
guest
12 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Paul L
Paul L
8 months ago

These are great tips. I have been working with PowerApps for about 2 years and I did not know most of these.

Sidhu Ram
Sidhu Ram
8 months ago

Thanks Matt. I have been using PowerApps for the last 2 months to build an app for my org, but never ventured into forms as my datacollection was more complex. Wanted to build a screen today for a simple user collection and update and your article is timely to adopt best practices in design. A big fan of your work, though I never got the opportunity to say so, since comments are restricted in other articles beyond 3 months from date of publishing 🙂

Krishna Rachakonda
Krishna Rachakonda
8 months ago

Very well written post with most important tips. Thank you for putting together.

Last edited 8 months ago by Krishna Rachakonda
tagaresomshekar
8 months ago

Thanks for sharing!!

Joe Bonomo
8 months ago

Awesome set of tips! Appreciate you putting this together

Michel
Michel
7 months ago

Is there a way to obtain the name(s) of the control(s) or the mandatory field(s) that prevent the Form.Valid function from giving a true?

In a multipage form, this would be really helpful.

Right now I use an Or with the !IsBlank(ErrorMessageXXX) to guide the user to the page where a field requires input, but it is not elegant.

Would also like to use the Focus function, but it seems Form and Focus don’t go together.

Last edited 7 months ago by Michel
Daniel
Daniel
6 months ago

Hi Mat,

This is a great post (I have read over it more than once, I come back when I am looking for something that I know that is here).

I have a question regarding this code

If(Form1.Valid, DisplayMode.Edit, DisplayMode.Disabled)

I have a screen that has several forms on it (I posted about it in one of your other blog posts) and I need to do that to all of then. To make it more tricky, in some cases not all of the forms needs to be submitted.

To make it easy for you to understand, the onselect for my submit button is

If(incident_check.Value = true,SubmitForm(incident_form));
If(property_check.Value = true, SubmitForm(property_form));
If(fleet_check.Value = true, SubmitForm(fleet_form));
If(improvement_check.Value = true,SubmitForm(improvement_form));
If(hazard_check.Value = true, SubmitForm(hazard_form));

Do you know of a simple way that I could have the .valid option while taking into account that not all forms needs to be submitted?

Thank you

Daniel
Daniel
6 months ago

Hi Matt,

Thank you so much for that, I wonder why I didn’t think of doing it like that 🙂

Thank you again