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

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
Highlighted
Memorable Member
Memorable Member

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



If this reply has answered your question or solved your issue, please mark this question as answered.

Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

View solution in original post

15 REPLIES 15
Highlighted
Community Support
Community Support

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.
Highlighted
Memorable Member
Memorable Member

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



If this reply has answered your question or solved your issue, please mark this question as answered.

Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

View solution in original post

Highlighted
Frequent Visitor

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.

Highlighted
Frequent Visitor

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
Power Apps
Power Apps

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

Highlighted
Frequent Visitor

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

Highlighted
Microsoft
Microsoft

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>
}

Highlighted
Memorable Member
Memorable Member

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



If this reply has answered your question or solved your issue, please mark this question as answered.

Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

Highlighted
New Member

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
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,005)