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

Populating a form value from a SharePoint list depending on selection of a dropdown field

I have a power app form that is dependent on 2 SharePoint lists (LABS_LIST and LABS_NAMES) The form I'm working on is used to update or create a new record in the LABS_LIST SharePoint list. I'm using the LABS_NAMES list to populate a dropdown and a text input on my form. The LABS_NAMES list contains the fields LAB_NAME and LAB_POC LAB_NAME is the name of the lab and LAB_POC is the person to contact for the lab. Example - LAB_NAME = "Southwest", LAB_POC = "Doe, John".

 

I'm populating the dropdown with all the lab names. When a user selects a lab name, I want the text input to be populated with the corresponding lab POCs.

 

So if I select Southwest as the lab in my Dropdown2 dropdown, then the text input DataCardValue29 for the lab poc would be updated with "Doe, John"

 

Here is my code for my dropdown (Dropdown2) - Code assigned to "Items"

Ungroup(
    Table(
        {LABMenuOptions: Table({'LAB_NAME': Blank()})},
        If(labRole = "POC",
        {LABMenuOptions: Filter(LAB_NAMES, 'LAB_POC'.Email=varUserEmail).'LAB_NAME'},
        {LABMenuOptions: LAB_NAMES.'LAB_NAME'}
        )
    ),
    "LABMenuOptions"
)

 

My code for the input (DataCardValue29) - Code assigned to "Default"

If(
    !IsBlank(Dropdown2.SelectedText.Value),
    Filter(LAB_NAMES,StartsWith('LAB_NAME',Dropdown2.Selected.Value)).LAB_POC,
    "Unknown"
)

 

So far my If statement for the DataCardValue29 input field has errors and when I test and make a selection in Dropdown2, the DataCardValue29 field is not updated with the LAB_POC's name.

2 REPLIES 2
Jeff_Thorpe
Super User
Super User

Without seeing the error for input, my guess is that the Filter() should actually be a Lookup() because the filter is returning a table column and the input field is expecting text.

 

Try this instead:

Lookup(LAB_NAMES,StartsWith('LAB_NAME',Dropdown2.Selected.Value)).LAB_POC,



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

I tried something different. The fields of my SharePoint list, LAB_NAMES are 'LAB NAME', which is a text field, and 'LAB OWNER' which is a person field.

 

For the OnSelect of the Dropdown2 form element I created a collection:

Collect(colLABNAMES, Filter(LAB_NAMES, StartsWith('LAB NAME',Dropdown2.Selected.'LAB NAME')));

 

That should return all the columns from the LAB_NAMES list where a specific lab name was selected above, basically a single record.

 

After I create the collection, I try to update the text of the TextInput1.Text field :

TextInput1.Text = colLABNAMES.'LAB_x0020_OWNER'.

However i get the error "Incompatible types for comparison. These types cant be compared: Text, Table"

 

Here is the complete code from my Dropdown onSelect:

 

Collect(colLABNAMES, Filter(LAB_NAMES, StartsWith(LAB NAME',Dropdown2.Selected.'LAB NAME')));

TextInput1.Text = colLABNAMES.LAB_x0020_OWNER

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,541)