cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Manually set lookup column in new SharePoint list item

Hi folks,

 

Due to SharePoint lookup columns taking forever to load into a dropdown on an edit form (a common complaint from what I've seen) I started to think about how I might do this a bit differently and pre-load those items.

 

So on my form, instead of the Standard Data Source card that is linked to the Lookup column, I put in a Custom Card which shows the pre-loaded items from the list in SharePoint which is the source of data for the Lookup column. All works well so far.

 

What I can't figure out is then how to save this as part of a new Item to a SharePoint list. On the form submit button, I have the following formula / functions:

 

 

Patch(timesheet, Defaults(timesheet), 
	{
		Title: "Time Entry",
		LookupCol: FormDropdown.Selected.Value,
		date: FormDateValue.SelectedDate,
		description: FormDescriptionValue.Text,
		hours: FormHoursValue.Text
	}
)

This didn't work, giving me an error message saying "The type of this argument 'LookupCol' does not match the expected type 'Record'. Found type 'Text'"

 

 

OK, to be expected and I thought easy to fix. So I put in a record instead:

 

 

Patch(timesheet, Defaults(timesheet), 
	{
		Title: "Time Entry",
		LookupCol: {Value: FormDropdown.Selected.Value, Id: FormDropdown.Selected.ID},
		date: FormDateValue.SelectedDate,
		description: FormDescriptionValue.Text,
		hours: FormHoursValue.Text
	}
)

 

 

and now the error message is "The type of this argument 'LookupCol' does not match the expected type 'Record'. Found type 'Record'".

 

I'm a little confused... Can anyone shed some light on why this isn't working and/or how to populate a Lookup column in a SharePoint list?

12 REPLIES 12
Community Support Team
Community Support Team

Re: Manually set lookup column in new SharePoint list item

Hi Jason,

 

According to this article about “Connect from Microsoft PowerApps to SharePoint”, Lookup column should be supported in PowerApps and data can be written to SharePoint list.

 

The article link is:                    
https://powerapps.microsoft.com/en-us/tutorials/connection-sharepoint-online/

 

Do you try with a simple Patch function to write data to a Lookup column which already exists in SharePoint list?

 

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.
Anonymous
Not applicable

Re: Manually set lookup column in new SharePoint list item

Of course, I had tried the 'normal' way of doing this which is why I complain of the Lookup list dropdown taking some time to load - motivating me to find a better solution.

Power Apps Staff rgruian
Power Apps Staff

Re: Manually set lookup column in new SharePoint list item

Hi Jason,


Once you have your SharePoint list imported as a data source in PowerApps, add a button to your canvas, and bind its OnSelect property to this:


     justaButton.OnSelect = Collect(timeSheetCollection, timesheet)

 

Then preview the app, and click on that button. This will populate the collection with full data rows from your SharePoint list. Next, click on Content, then Collections. Select 'timeSheetCollection' and inspect its schema. This will give you an idea of what is expected for valid new rows for your SharePoint list, including its lookup fields. For the latter, click on the "table" icons to descend into the coresponding record values and see their respective fields.

 

I hope this helps.

 

 

 

 

Radu Gruian [MSFT] ** PowerApps Staff
DHoxeng
Level: Powered On

Re: Manually set lookup column in new SharePoint list item

I am having the exact same issue as Jason.

 

I have a List with a column that is a type Choice. I have created a collection that matched the values and Ids on the poweapp. 

 

When setting up the Patch I did as Jason did, but I am getting the same issue.

 

My code:

 

Patch(..., SWPPPLocatedOnsite:{Id: drpSWPPPLocated.Selected.Id, Value: drpSWPPPLocated.Selected.Value}, ...) 

 

So I followed the steps that rgruian supplied was able to get the schema from the list.  The choice column showd the Id and Value as expected, but it also has an @odata.type column.  I am not sure that I am to do anything with this.  I have played around with it a bit, but the patch does not like the column name.

 

Any help would be appreciated.  

Power Apps Staff rgruian
Power Apps Staff

Re: Manually set lookup column in new SharePoint list item

I am trying to understand what you mean by "Patch doesn't like the column name"? Have you wrapped the @odata.type column name in single quotes, to account for the non-alphanumeric characters?

 

For example:

 

Patch(..., { SWPPPLocatedOnsite: {'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Id: drpSWPPPLocated.Selected.Id, Value: drpSWPPPLocated.Selected.Value}, ...}, ...)

 

In your formula, you need to specify a record for the third parameter to patch. One of the fields in that record will be the lookup field, which is a nested record itself. In that nested record, one of the fields will be '@odata.type', as shown above.

 

I hope this helps.

 

Radu Gruian [MSFT] ** PowerApps Staff
DHoxeng
Level: Powered On

Re: Manually set lookup column in new SharePoint list item

Of all the things I tried, apparenltly I missed the single quotes for the @odata.type!  That did the trick!  Thank you so much for your help!

Power Apps Staff rgruian
Power Apps Staff

Re: Manually set lookup column in new SharePoint list item

Glad to hear you are unblocked. Thanks for reporting back.

 

Radu Gruian [MSFT] ** PowerApps Staff
cquick
Level: Powered On

Re: Manually set lookup column in new SharePoint list item

I can see how this works, but I don't understand how to get a list of available choices from a Choice field. I want to create a screen that automatically includes the available choices and then use that selection to perform a PATCH to the list. When I create the button as described:

Button1.OnSelect = Collect(workOrderStatusList, 'Work Orders')

It populates the collection and I can easily see the schema as described. However, if I bind a gallery to the workOrderStatusList.Status column (a choice field with 6 available options), I get the current status of the current item. Is there a way to get all of the available choices, or should I just create my own collection with those choices. I would hate to do this because I now have to maintain choices in two places.

 

Power Apps Staff murali
Power Apps Staff

Re: Manually set lookup column in new SharePoint list item

You should be able to use

 

DataSourceInfo(YourDataSource, DataSourceInfo.AllowedValues, "FieldName")

 

to get all available choices.

 

Thanks

Murali

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Users online (3,374)