PowerAppsPuzzle: @ vs # == Cryptic Error

Hey folks!  We are back with another PowerAppsPuzzle this week. This time we are trying to track down the source of a very cryptic error message. I am working on a solution for a PowerApp that integrates with SharePoint Online and for this particular solution I cannot rely on the built in form functionality that we get when using the wizard -- "App from data". So this time I had to manually create the form by adding controls to a screen and then using the Patch() formula.

As of the time of this blog post, some of the functionality is still evolving and in order to Patch() a SharePoint list that contains certain fields -- like Choice, Lookup, Person -- you need to supply some extra context in the form of records. Here is one example:

Patch(Cars,Defaults(Cars),{Title:TextInput1.Text, Color:{'@odata.type':"@Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Value:Dropdown2.Selected.Value,Id:LookUp(testCollection1,Title = Dropdown2.Selected.Value).ID}, Manufacturer:{'@odata.type':"@Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Value:Dropdown1.Selected.Value} })

So in the sample code above, I'm attempting to patch a SharePoint list that contains Title (single line of text), Color (lookup), and Manufacturer (choice). A simple field like Title is easy enough, you simply pass the data you want to update in that field. For the other two fields we need to define more information. So for Color, we pass the @odata.type in addition to the Value and ID.

There are plenty of blogs and samples of how to do this, but whenever I executed Patch() I was greeted with the following error:

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

Well... this wasn't very helpful in and of itself so I started scouring the net and stumbled on the following discussion thread: https://community.powerapps.com/t5/PowerApps-Forum/Not-able-to-Update-Dropdown-value-to-a-sharepoint-List/td-p/13550

Towards the end of the thread is where I found my solution. I'm curious who has seen it in my sample code above? The corrected code is:

Patch(Cars, Defaults(Cars), {Title:TextInput1.Text, Color:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Value:Dropdown2.Selected.Value,Id:LookUp(testCollection1,Title = Dropdown2.Selected.Value).ID}, Manufacturer:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Value:Dropdown1.Selected.Value} })

In case you still miss it (as I did for quite a while). The key is in the @odata.type. The actual value should be prefaced with '#' instead of '@'. One of the reasons this was such a challenge is that it wasn't flagged as a syntax error.

Hope this helps someone else along the way!

Happy PowerApping!