cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kfesenko
Level: Powered On

Set Default Value for Lookup Field in New Form

My project is an inventory management system, using two SharePoint lists; TBL_Locations and TBL_Assets. TBL_Assets has a lookup column called "LocationNumber" to a column in Locations called "LocationNumber".

 

I have created a standard app from the TBL_Locations list, and added a gallery to the second screen which shows the assets for the specified location.

 

I've added a button which opens the form to create a new asset. It doesn't really make sense to have a user select the LocationNumber manually since they have already selected a location to be working from, so I'd like to have that field automatically populate based on the Screen_Location.Selected.LocationNumber value.

 

However this doesn't appera to be quite a straightforword as I would expect, and I haven't been able to follow the other discussions on similar topics in this forum to achieve this goal.

 

Cheers,

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Set Default Value for Lookup Field in New Form

Hey @kfesenko

 

 

Maybe this could solve your problem to populate the dropdown.

So you have a selected item from your gallery and want to fill in a value from the dropdown that is linked to the selected item right.

 

So what you could do is this:

First(Search(<DataSource>,<GalleryName>.Selected.<Field>.[Text],"<Field>")).<Field>

The .Text is optional if it is already a text field.

 

Hope this helps 

 

Kind regards

 

 

Tom





Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!





View solution in original post

13 REPLIES 13
Community Support Team
Community Support Team

Re: Set Default Value for Lookup Field in New Form

Hi Kfesenko,

 

Is Screen_Location a screen with a Gallery control?

 

Do you want to create a NewForm to add new records to Assets list? And on the NewForm, you have a Dropdown control that you that you want to show the LocationNumber based on the Screen_Location.Selected automatically without selecting from the drop down items.

 

Please feel free correct me if I misunderstand you.

 

Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: Set Default Value for Lookup Field in New Form

Hey @kfesenko

 

 

Maybe this could solve your problem to populate the dropdown.

So you have a selected item from your gallery and want to fill in a value from the dropdown that is linked to the selected item right.

 

So what you could do is this:

First(Search(<DataSource>,<GalleryName>.Selected.<Field>.[Text],"<Field>")).<Field>

The .Text is optional if it is already a text field.

 

Hope this helps 

 

Kind regards

 

 

Tom





Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!





View solution in original post

kfesenko
Level: Powered On

Re: Set Default Value for Lookup Field in New Form

I can't seem to even get the search function working. It keeps saying that I'm using invalid arguments but as per the documentation I'm supplying a table, search query, and column. Here's a screenshot of my windowimage.png

 

I'm not sure how much it's worth troubleshooting as for the time being I have stopped using the lookup column due to it not being supported for delegation.

kfesenko
Level: Powered On

Re: Set Default Value for Lookup Field in New Form

@v-yamao-msft

Yes to all of your questions. That is exactly what I'd like to do.

Highlighted
PowerApps Staff AndyPennell
PowerApps Staff

Re: Set Default Value for Lookup Field in New Form

You need to remove the quotes around Location Number. It needs a column name ie LocationNumber

kfesenko
Level: Powered On

Re: Set Default Value for Lookup Field in New Form

@AndyPennell

Still no good. Also according to this page "Filter, Search, and LookUp functions in PowerApps"  the 3rd argument in Search should be used like so: 

  • Column(s) - Required. The names of columns within Table to search. Columns to search must contain text. Column names must be strings and enclosed in double quotes. However, the column names must be static and cannot be calculated with a formula. If SearchString is found within the data of any of these columns as a partial match, the full record will be returned.

Also note that the "Center Number" field is the same as "LocationNumber". I added it in there to get the app to work properly. It's just a regular number column and not a lookup.

image.png

Microsoft Employee

Re: Set Default Value for Lookup Field in New Form

This is definitely NOT the best approach to do, but I created a object with values needed on the LookUp object to be added to form.

 

The default property looks like this:

 

{
    '@odata.type' : "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
    Id : <id_from_the_item_in_the_lookupfield>;
    Value: <value_you_want_to_show>
}

Super User
Super User

Re: Set Default Value for Lookup Field in New Form

Hey @kfesenko

 

 

If you use First(Search(...))

You need to put a field after the bracket from the function First like this

 

First(Search(TBL_Locations,Gallery.Selected, "LocationNumber")).LocationNumber

 

Kind regards

 

 

Tom





Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!





johesmil
Level: Powered On

Re: Set Default Value for Lookup Field in New Form

I'm having the same problem, and I tried your suggested solution @Tom_Slosse. And while I managed to get the dropdown to successfully show item I want as a default, I receive an error upon submitting the form:

"The requested operation is invalid. Server Response: A value must be provided for item".

A quick search for the problem didn't give a lot of info, besides the problem arising for someone using a people field (which behaves the same way due to it also being a sort of lookup). I was wondering how you managed to get this solution without running into the same issue I did? Are there any other steps besides setting the default value? Do you combine this with another method of saving the data besides SubmitForm()? Like Patch for example, which I have seen referenced sometimes, but haven't tried using myself yet.


Second question to @camel:
I've tried your solution as well, adding the bracketed odata-thingy as the Default property of the dropdown connected to the SharePoint Lookup field. But contrary to the above solution, this gives me the following error:

"The requested operation is invalid. Server Response: Value cannot be null. Parameter name: source"

So the same applies here. The default value I want is set successfully, but I can't submit the form. Any ideas?

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 327 members 6,107 guests
Please welcome our newest community members: