InfoPath and SharePoint Web Services: GetListItems

I've been working on an InfoPath form (which has been driving me crazy to say the least).  I needed a collection of list items for the current user so I started by creating a data connection to my list, displaying it in a repeating table, and hiding what I didn't want to see.  (I know, sloppy).  It worked, but my client uses IE8 and it would throw JavaScript errors if it had too pull to many list items.  (IE10 and Chrome worked fine).  The form would eventually load, but that was no good.

I then tried using web services, specified lists.asmx, and attempted to use the GetListItems operation.  No matter what I did, I got the following error message:

The SOAP response indicates that an error occurred on the server:
Microsoft.SharePoint.SoapServer.SoapServerException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
Element <Query> of parameter query is missing or invalid.0x82000000

I dug around and it appears to be a common issue but I haven't found an alternative suggestion so I gave REST a try.  

Start by selecting "From REST Web Service" 

Next, enter the URL followed by "/_vti_bin/listdata.svc/<Your List>" (you should be able to add your filters here but in my case, I need it to be a little flexible so we'll do that in a bit).


Now, you can access all of the data but like I said earlier, I needed to filter the data so here's how I did it by using Rules.

Create a new action based rule.  The action that we'll need is "Change REST URL"

We'll need a function to change our URL.  I started by using concat.  There's an existing SharePointSiteURL() function that will return the URL of site where the form resides.  That function gets passed into the concat first, and fill in the rest of the concat function as needed.  In the image below, my field names aren't showing up, but they're there.


The last thing we'll need it to query the data again.  Just create another rule. Select "Query for Data" in the list of actions, and choose your REST Web Service.



Labels: , , ,