Latest Posts

PowerApps canvas - Coding Standards and Guidelines


In this article, we are going to see some basic coding standards that every developer should follow while working in PowerApps as part of programming best practice.

Naming Conventions

Note: Following these naming conventions ultimately increases the readability of the code and will lead to faster development.
  • Don’t keep spaces in the names of the variables, components, screen/page names, databases, etc.
  • For PowerApps controls you can use Camel Case naming conventions as mentioned in the example below.
    • Textbox – txtFirstName
    • Drop Down list – ddlCountries
  • For Databases used in PowerApps you can use Pascal Case naming conventions as mentioned in the example below.
    • SharePointDB
    • SQLConnectionDB
    • OracleDB
  • Meaningful Screen Names: Everything in Canvas apps starts with screen. Make sure you give meaningful name to all your screens.
    • By default, when you create a screen, it comes with names like, Screen1, Screen2. Now if it is a small application having just 2-3 screens then it won’t be much difficult but assume you are having 5 modules in the application and each module has 20 screens, you will end up wasting 15 mins every time you start the work.
  • Repeating control names: If there are multiple controls having similar behavior placed on different screens.
    • E.g., txtFirstName: let’s say we have first name field from 2 different table and used in 2 different screens. In these cases, it is advisable to use screen name along with control name to easily identify them.
      • SubmitScreentxtFirstName,
      • HomeScreentxtFirstName
    • For PowerApps Variables: Your team needs to be consistence in creating the name.
      • Like for string variable strAddressDescription, for Integer variable intRoleNumber. Some people choose to add an underscore to group them like str_FullName. The point is whatever you choose, be consistent throughout the application.
      • You can prefix local/context variable with loc - locNavigationURL
      • You can prefix Global variable with glb – glbLoggedInUserName
    • Collection: Always prefix the collection variable with either coll or col: collStudentsList or colFileNames

PowerApps Organization

  • Grouping: If you keep your controls of the screen, within a group, it will be easier to move them between the screens. You can collapse and expand the groups, it will simplify the view.
  • Format Text Feature: This feature is used for the better readability of the code. When length of the code increases this feature is very useful to understand the code quickly. This feature adds the line breaks and indentations in the code.

PowerApps Performance Improvement

  • Concurrent Function: Use Concurrent function to run multiple methods parallelly. This function is easy to use and will increase the performance of the app.
  • If you are making frequent delegable calls, it is best that you bring the data from the database here and you can store the data into a collection. Now you can use this collection efficiently.
  • Try to avoid implementing heavy logic in OnStart method of the Canvas App. Instead of that, you can navigate from the home screen and use OnVisible property of the other screen.
  • Don’t spread you code across multiple screens.
    • E.g. Let’s say there are 3 integers, and we need to do multiple calculations (additions, multiplications) with them.
      • Now, you are on Screen 1 having those 3 numbers and the result screen is Screen 2. Instead of sending the calculated result, what you can do is just send all the 3 numbers as mentioned below from Screen 1 to Screen 2 and the calculations with be done on Screen 2.
    • Avoid putting large/heavy code in OnSelect property. If the code takes time to execute, it gives impression that the app is stuck. Incase heavy code is unavoidable then try putting screen loading icon or give some message.
    • Same way for Screen OnVisible property also. Avoid putting heavy code in this property instead you can wit proper formulas for the controls.

PowerApps General Coding Guidelines

  • Same formula/function for multiple controls: Let’s say you want to execute a method from two or more buttons, how would you do it?
    • First approach: Write formula in OnSelect property of one button (e.g. Button1). Now in Button2 (The other control) OnSelect property write formula as mentioned below.Select(Button1).
    • Second approach: Group all such control together and write the formula on Group’s OnSelect property.
  • Reduce the number of variables:
    • Use a global variable when you need it to be available on all screens.
    • Use a context variable if you want to limit the scope of a variable to a single screen.
  • UpdateContext: You can update multiple context variables in single call.You can write like this

Instead of

  • Collections: Limit the use of collection.
  • Collections: Use ClearCollect() instead of Clear();Collect();
  • Collections Count: Use CountIf() formula instead of using Count(Filter())

We value your Feedback:

Page URL:

Name:

 

Email:

 
 

Suggestion:

 

© 2024 Code SharePoint