
If you create a PowerApp and look around on the internet for solutions, you will come across the following functions from time to time.
- Set()
- updateContext({})
- with()
- navigate(…,…,PARAMETER)
- param()
- Addition: If you want, you can also add a collection (Collect, ClearCollect).
In the following, I will show you briefly what I use them for and why you should think about using them too.
- set() function
This is probably the best known function of all. It sets the value of a global variable. Global variables are useful when you want to store a value and use it on different screens. This can be used in the OnStart, where you set style variables, the logged in user or if you select an element from a gallery and want to use this element somewhere else.
Set(
varUser,
user()
)
- updateContext({})
This is the little brother of the Set function. Sets the value of one or more context variables of the current screen. I mainly use this when I want to change a value (true,false) to show/hide something, for example. Mostly a pop-up or another input window.
Here I set the variable “locPopUp” first to “true” and then again to “false”.
UpdateContext({locPopUp: true});
UpdateContext({locPopUp: false})
- with({})-function
This function I discovered some time ago and is again the little brother of UpdateContext. Here “variables” are stored exclusively for a function and can only be referenced in this function. I use this mainly within functions, as soon as I have to use a certain function several times.
In this example, I write the variable “locText”, to which I then reference 2x in the further course of the function. Important: the With function is closed only at the end of all functions.
With(
{locText: TextInput1.Text},
If(
IsBlank(locText),
“noText,
TextInput1.Text
)
)
- navigate(…,…,{PARAMETER})
This parameter was unknown to me for a long time, because I usually stopped after the first comma and closed the parenthesis. But if you put two more commas after the Navigate, you can pass one or more parameters to the screen you want to navigate by using the curly braces. This parameter is then only available on the following screen. (unless you write it into another variable or pass this value again)
In this example, I pass to Screen1 the parameter “locVariableNextScreen” with the text “Yes we can use it”.
Navigate(
Screen1,
UnCover,
{locVariableNextScreen: “Yes we can use it”}
)
- param()
This provides access to parameters passed to the app when the user has it open. This parameter is usually used less often, as this is exclusively appended to the app’s URL. Thus it is possible to navigate the user to a certain page or to pass certain values to the app.
Here, I pass the parameter “Admin” with the value “true” in the URL. In OnStart I then set the global variable “varAdmin” with the parameter “true”. So I can enable additional settings for an admin, using this parameter. (Visible: varAdmin)
https://apps.powerapps.com/play/543654354453543543?tenantId=dasfdgdsgsfsdfsdf&Admin=true
Set(varAdmin,Param(“Admin“))
Extra tip: If you use a variable and want to use it as a boolean, which is always the opposite of the current state, use the “!” in front of the variable. This reverses the value.
This example reverses the value every time it is executed. If is currently true, it will be changed to false and vice versa.
UpdateContext({locPopUp: !locPopUp})
Leave a Reply