Power Apps Global Variables - Stop using them!

preview_player
Показать описание
In this video, we will explore the benefits of using the With function in Power Apps over using global variables and the Set function. The With function is a powerful tool that allows you to make multiple changes to your app in a single function, rather than making each change individually. By using the With function, you can improve the performance of your app and make your code easier to read and understand. We'll also discuss the limitations of global variables and the Set function, and how the With function can help you avoid these pitfalls. So join us as we learn about the benefits of using the With function in Power Apps. #powerapps #powerplatform #office365
Рекомендации по теме
Комментарии
Автор

Very good information and I appreciate the effort to share. I would personally like it better without the background music. Others may feel differently. Thanks again!

ryan
Автор

I thought the focus might be limited to ‘update context’ but ‘with’ was used and explained well. Thank you.

geralddahl
Автор

Awesome video, I just learned something new. 👍

valentineelias
Автор

GREAT! I Appreciate You Chino… THANK YOU!!!

EpicBizHero
Автор

Great video! I have a question. When should you use With and when should you use a local variable?

InComa
Автор

Don't stop using global VARs. Here's why...

The first global VAR you created was a new one. When creating the second SET() function using the same VAR name, the designer SHOWED YOU the name you were typing already exists. It was on the list below where you were typing. So now you have a choice. Use the existing VAR or create a new one with a different name.

To find where a VAR has been used across the app, use the SEARCH FUNCTION on the left NAV bar. It will let you see and navigate to every place in code, across the entire app, that the VAR has been used. Also, if you don't like the "varName" you used, you can use the designer "Search and Replace" functionality to update the VAR everywhere with a new and improved name.

When you talk about a large app with 100s of VARS, it is only a problem if you don't have a good VAR naming convention. VARs need a name that has meaning when you read it six months later or that someone else will understand without requiring documentation. In your example you used "recID". A better name would have been "varCreatedIssueID_record" since that is what is returned from a Patch statement. Also you used "varStatus" a very generic and unhelpful name. "varIssueStatus" would be meaningful and easier to understand. Make a VAR name as long as it needs to be so that it is understood by all who read it. There is no reason for a short meaningless VAR name. This isn't programming Power Apps 1979.

In your status example your code referred to what item was selected in the control. A better way would be to use the OnChange property of the control to SET a global VAR that you use in your Patch code. It is a bad habit to use a reference to a control property. If the control is not on the current screen, your app has to keep every other screen you have referred to in memory which is a performance hit. Early on, I made this mistake based on seeing the same idea shown in canvas app videos I watched on YT, now I am having to revisit every line of code to "fix" this issue. Also, this issue gets more complex when you set a default value for the control. The user may or may not select anything. So now, nothing is selected but your code isn't using the default value. Also, Microsoft in their docs say don't do this and the App Checker will issue warnings about the issue.

In the last three years of developing Canvas apps, I have yet to have anyone explain why I should ever use a context var. IMO, just a waste of test and complicates refactoring of an app. For example, when you move some, but not all controls from one screen to another. for a better user experience.

The With() function has it place, and can be a big help, in more complex Patch code. Personally, I wouldn't use it with the code you showed, it just creates more lines of code to read.

Hope this is helpful to others.

artkarp