Power Apps Controls and their References
Contents
General
When you start your Power Apps journey and start working with controls and their inputs and output references, there is a lot of confusion and misunderstanding that can be quite easily alleviated, saving you both time and potential errors.
Initially, you had probably “left them alone” with the settings Power Apps provides when they were created, used SubmitForm() to save the data and all worked exactly as you expected. Now you are needing to refer to them in code and possibly change the settings in the control itself to meet your needs. All of this should not be overwhelming if you take a little time to understand a few basic things.
The first thing to do is to properly name any control containing data. I have done a blog on this which may be useful for you to read first.
Once you have names you will easily remember, the next thing to use is the built-in IntelliSense function, which will become your best friend when coding. It is the box that appears under where you are typing and offers valid values to choose from. Be aware you can easily write non-functional code as it has no idea “where you are heading”, but it will only offer invalid values.
Outputs
These are the values the control’s content produces when referring to them in either code or the Update of the card in which it lies. Going through the various “Static” types – (Name = the control’s actual name)
Most commonly used
Label (Text) | Name.Text |
Label (Number) | Value(Name.Text) |
Text Box (Text) | Name.Text |
Text Box (Number) | Value(Name.Text) |
Date Picker | Name.SelectedDate |
Check Box | Name.Value |
Toggle | Name.Value |
Other controls
Pen Input | Name.Image |
Camera | Name.Photo or Name.Stream |
Image Control | Name.Image |
HTML Text Box | Name.HtmlText |
Rich Text Editor | Name.HtmlText |
Barcode Scanner | Name.Value |
Now proceeding to the “dynamic” controls
- Drop down
- Combo Box
- List Box
- Radio Control
All of these provide a “list” of items that can be obtained from a variety of sources from Choice and (if you must but only with a Combo Box Lookup) fields to collections and directly coded values. The output of these controls is always
Name.Selected.xxxx
But it is the xxxx that needs understanding. Putting aside that IntelliSense will present this to you when you type Name.Selected. (note second “dot”), the following is a summary of the possible values.
NOTE xxxx will be referred to throughout this blog and requires substitution as below.
There are three possibilities (referring to the Items property of the control)
If you have hard-coded the Choices, or the source is a Choice or Lookup field, the output will be
Name.Selected.Value
If you have used a Distinct() filter to arrive at the output
Name.Selected.Value
If you have based the output and displayed the choices on a field name, it will be
Name.Selected.FieldName (the actual field name)
You will use these values whenever referring to the control’s output.
Data Source Fields accepting this output
This is another subject that if properly understood presents little difficulty in sending your data back to the desired place in the data source.
I have provided some guidance in my blog on structure planning. Firstly, if you have Text, Date or Numeric fields in your data source, whether you are using SubmitForm() or Patch, the references above will write back and store as you expect.
If however you have “complex” field types, which are actually tables, then additional “treatment” is required.
Choice
Here, you have one field in the table Value, so (for a single choice), to write back (assuming this is coming from a “dynamic” control), you need
{Value: Name.Selected.xxxx}
For a multi-choice
ForAll(
Name.SelectedItems,
{Value:xxxx}
)
Lookup
Here, it is a bit more complex as what you are actually writing back is the ID of the item in the other list being “looked up”. Please also refer to the blog mentioned at the start and ask yourself do you really need this field type in your data source.
Firstly, this will only work in a Combo box due to its ability to hold record values and the obligatory item you must have is this ID “available” in the Items of the control (this discussion will not cover the complex workarounds when this is not the case).
For a single choice
{
Value:Name.Selected.xxxx
Id:Name.Selected.Id
}
Multiple selections
ForAll(
Name.SelectedItems,
{
Value:xxxx
Id:ID
}
)
Defaults of controls
This is what the controls display – normally you will see Parent.Default, but if you have to change this, you need to understand the reference from the data source that will display correctly and ultimately properly write back to the data source – very important if you do not change the value and use SubmitForm().
I the case of the “Static” Controls, this will normally be simply
ThisItem.FieldName (actual field name)
When dealing with Complex field types, the source is a table and the same principle needs to be referenced.
For all “dynamic” controls other than a combo box you can generally reference this as
ThisItem.FieldName.Value
but one very important thing – the item displayed MUST be in the schema or choices available in the control to display. You will get no error if not, but simply have a blank control.
The Items of Combo Boxes are in themselves a table, so you have a “double reference” to deal with. Also the value to be addressed is DefaultSelectedItems, not Default. Firstly for a single choice control
{xxxx.ThisItem.FieldName.Value}
For a Multi Choice field – (you are putting a table into a table)
ThisItem.FieldName
Conclusion
Note that is general guidance discussing the most common interactions with controls and may not completely cover all possible complex code. I hope it allows greater understanding of some of the fundamentals you need to know in your Power Apps journey
2 Comments
David
Greetings, as a point of reference, I know nothing about Coding (shame) and I have been tasked with creating an app that would control a SP list in terms of allow/disallow a user to input equipment request. I want the app to be controlled by a complex choice field, start date field, and an end date field. This is what I have so far:
If(
!IsBlank(
LookUp(
[@’MRDB Test Calendar’],
‘Test System’=DataCardValue8.Selected.Value &&
‘Start Date’=DataCardValue11.SelectedDate
).Status
),
DisplayMode.Disabled,
DisplayMode.Edit
)
Thanks in advance,
Mr Nubee
Warren Belz
Hi David,
Please post this on the Learn forum