Power Apps – Get Values from Multi-Select Fields

Most of the times in custom list forms or in web power apps you have a requirement to perform an action based on values selected in a field. It is very straightforward for simple fields like single line of text, number, single-select drop-downs but gets little tricky if the field is multi-select. For example, in a demo application, I want to enter my details along with my hobbies. Let’s say the condition is; if “Reading” is one of my hobby, I need to ask user his/her preferred book format. If not, this field should not be visible. Below post is about achieving this.

Currently the form looks like this:

I need to display “Book Format” field only when I select “Reading” as one of the “Hobbies”.

  1. The first logical step is to record the selected hobbies in a variable. We can bind it to the “OnChange” event of the “Hobbies” drop-down. It can simply be achieved by using the UpdateContext function

    UpdateContext({SelectedHobbies: HobbiesDropDown.SelectedItems})The above statement declares a variable named “SelectedHobbies” and set its value to selected items in the drop down list. I have renamed the data card value to “HobbiesDropDown” for ease of use.

  2. The above variable “SelectedHobbies” is of “Table” type. If you are confused, you can confirm the type of variable by selecting the “File” menu item and checking “Variables” section
  3. Now it is just a matter of checking if “Reading” is one of the value in “SelectedHobbies” table variable and then set visible property of “Book Format” drop-down accordingly. To check this, you can use LookUp function present in Power Apps. I used the below query:If(LookUp(SelectedHobbies, Value = “Reading”, Value) = “Reading”, true, false)

    What it says is, if “Reading” is one of the “Value” present in the “SelectedHobbies” table, then set visible property of “Book Format” to true else false. Notice the use of “Value” keyword here. LookUp searches the given collection (first parameter), based on a condition (second parameter) and return the field you want (third parameter) satisfying that condition. In our case, if “SelectedHobbies” collection has Reading as its one of the values, then return that particular value i.e. “Reading”.

  4. That’s it and you are done. Run your application to check.”Reading” not in the hobby list

    “Reading” selected as hobby:

Simple enough. I was going through multiple ways to do it when I stumbled onto the “Value” keyword. I did not find much documentation on this and hence the blog post. Needless to say, same behavior applies to power apps list form too.

Also, you can either replicate the same behavior in View and Edit form or use the Set function to create a global variable instead of UpdateContext which you can use across the app.

P.S. The above will not work for multi-select people picker column. It works for Choice and LookUp fields only.

Hope it helps!

Advertisements

Power Apps – An entry is required or has invalid value

Recently I started exploring Power Apps in more depth. Its a nice tool but not without some issues. My scenario was to create a power app based on a SharePoint list which uses a custom content type. All the fields in the content type were optional. But still when I tried to save the form, it gave classic “An entry is required or has invalid value” exception.

Generally this error means that a required field is missing a value but I have no such fields in my content type. Also, strangely, I was able to save an item using the default new list item form.

Update (July,2018): I tested this again and now even the default list form throws error.

All the fields in the power app has “Required” property set to “false”. All the fields in the custom content type were “Optional” and I had only one content type present on the list.

After wasting almost 2 hours on this, I realized that power app, unlike default new list item form, does not take content type “Required/Optional” attribute into account. It gives preference to column settings. So in my case the erroneous field was “Title” column. It was optional in content type but not in column settings.

 

 

 

 

As soon as I set this to “No” in the column settings, my power app worked perfectly. You might have some other column like this, so please check.

P.S. I encountered the same for Power Apps list forms.

Hope this helps!