PowerApps: Set SharePoint Lookup Field
In many solutions, we need to be able to set the values of fields via logic in our form, and we don’t always need the end user to pick from a drop-down box. The most common example is the relational database and parent-child relationships. When we build this type of thing in SharePoint, you would want the end user to have the master record on a form on the screen, and they should be able to quickly add child items to a sub-list (like repeating table style) on the same page. A common example is an expense report with expense items in a sub-list.
I’ll be writing out the whole cascading drop-down thing in a separate post, but in this example, the end user has selected the name of a project from a gallery of projects, and when they submit their timesheet form, that has a lookup field to the associated project, we need to set the value of that selected project, to the “Project” lookup field. Seems pretty simple, and you may be surprised, but currently it’s not that simple.
I’ve named my gallery ProjectGallery, and it shows items from a data source that is my SharePoint list called “Projects”.
In my timesheet form (using the form control in PowerApps), its data source is a SharePoint list.
Unlock this card in the advanced pane on the right.
Update 12/5/2017: Click to select the card.
Click to select the actual drop-down control as seen in the photo above. (don’t select the card, select the drop-down itself)
After we’re done configuring it, we can just hide the whole card.
What you’ll need, is the Title and ID of the project that you need to set in the drop-down or combo box control in this card.
In the Default property of the card, type this, using the name of your own gallery:
(do not copy/paste this text from my blog here, it doesn’t translate correctly into the PowerApp. Just type it manually in your PowerApp)
Id : Value(ProjectGallery.Selected.ID),
Yes, it’s ugly. Go ahead and set the Visible property to false for that Project card.
Now, when you submit a timesheet, the project you selected in a gallery will post in the timesheet form’s Project lookup field.
Here’s my full hour-long demo of how to build this, and how to build it with drop-down boxes instead of galleries: