cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
holtma
Frequent Visitor

Using Lookup for Conditional Visibility of Other Fields

Hi Everyone,

 

I am struggling with leveraging lookup columns in app that I am building. I have a simple form based app where people can enter business travel information such as address, cities to be visited, contact details of hotel etc.

 

I want some fields in the form to be visible/required based on the value selected in the "DestinationCountry" field. The choices in this dropdown come from a separate list which contains a list of countries (the values in the dropdown) and a "CountryRiskLevel" choice column, where the choices are High, Medium, Low. Therefore, each country has a risk level associated with it.

 

Would it be possible to make some fields required/visible only when the user selects a country which has a risk level of "High"?

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Aapok
Resolver II
Resolver II

You can try:

 

On the onChange of your dropdown:

                                                                                                                                             

UpdateContext({varRiskLevel: First(Filter(List2, DestinationCountry = dropdown.Selected.Value)).RiskLevel})

Note: Depending on how you fetch your data to the dropdown, Selected.Value might not be correct syntax. I also don't know the exact names of your columns, but this should give you a general idea how to achieve what you're trying to do.

 

Then in each of your form items Visible property, you can use the Switch function to define their visibility:

Switch(varRiskLevel, "Low", false, "Medium", false, "High", true)

 

There might be errors in my syntax, I wasn't able to test the solution.

 

View solution in original post

4 REPLIES 4
phipps0218
Memorable Member
Memorable Member

Yes. 

 

The field that you want to be visible or required can have an IF statement. For example:

 

Dropdown 1 > Go to the Visible Property > If(NameOfDestinationCountryField.Selected = "X", true, false)

 

Please Accept as Solution if it solves your question. Or just give it a Thumbs Up if it is helpful as can help others.

LinkedIn: https://www.linkedin.com/in/charlie-phipps-%F0%9F%91%A8%E2%80%8D%F0%9F%92%BB-91338715b/
Subscribe to my YouTube: https://www.youtube.com/channel/UChmFBGU1YKIU91sNMQ7buGg



Hi @phipps0218 , thanks for the suggestion!

I am not sure if this will work in my scenario - maybe I can explain differently.

 

The form is based on a simple SharePoint list (let's call it List1). However, the "DestinationCountry" column, which is feeding the dropdown choices in the form, is actually a lookup column to another list (let's call this list List2). List2 has two columns, one with a list of countries and the other with a risk level for each country (low, medium, high).

 

What I want to do regarding conditional visible/required fields - when a user selects a "DestinationCountry", I would like the form to look up the risk level of that country and use that risk level to determine which fields are required.

 

For example - if a user selects the USA as their destination country, the risk level will be "Low" and therefore they wont need to fill out the entire form. If the user were to select a country which has a "High" risk level, the form will need to make certain fields mandatory.

 

I hope that this is clearer, thanks again for the help!

Aapok
Resolver II
Resolver II

You can try:

 

On the onChange of your dropdown:

                                                                                                                                             

UpdateContext({varRiskLevel: First(Filter(List2, DestinationCountry = dropdown.Selected.Value)).RiskLevel})

Note: Depending on how you fetch your data to the dropdown, Selected.Value might not be correct syntax. I also don't know the exact names of your columns, but this should give you a general idea how to achieve what you're trying to do.

 

Then in each of your form items Visible property, you can use the Switch function to define their visibility:

Switch(varRiskLevel, "Low", false, "Medium", false, "High", true)

 

There might be errors in my syntax, I wasn't able to test the solution.

 

holtma
Frequent Visitor

Hi @Aapok - thank you, this works!

 

I only had to make one small change as the "CountryRiskLevel" column in List2 is a choice column and not text. Therefore on the OnChange property of the country dropdown, I made the following adjustment:

 

UpdateContext({varRiskLevel: First(Filter(List2, Title = Dropdown.Selected.Value)).CountryRiskLevel.Value})

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,077)