Lists.asmx and Microsoft’s creative documentation | Jesse Fewell

Lists.asmx and Microsoft’s creative documentation

By July 14, 2006Blog, Uncategorized

I’m currently working on a project which utilizes Microsoft SharePoint web services. Let’s say I maintain a Risk Management spreadsheet as a list in SharePoint. Microsoft’s documentation says you could use the GetListItems web method to query the server for any mish-mash of entries in that list. The documentation claims that this web service thing-a-ma-jig supports “arbitrarily complicated queries”; DON’T YOU BELIEVE IT.

First of all, they never tell you to group the criteria in pairs So let’s naively slap four criteria up against each other, like this:


< where>< and>< eq>< fieldref Name="Group_x0020_ID" />< value Type="Text">0109001001< /value>< /eq>< eq>< fieldref Name="Plan_x0020_ID" />< value Type="Text">RNR01A< /value>< /eq>< eq>< fieldref Name="Document_x0020_Type" />< value Type="Text">SMM< /value>< /eq>< gt>< fieldref Name="Effective_x0020_Date" />< value Type="DateTime">2/16/1992 12:15:12< /value>< /gt>< /and>< /where>

The server will return to you an error of type Microsoft.SharePoint.SoapServer.SoapServerException. This inherits from System.Web.Services.Protocols.SoapException, which gives you more a litte more info in the Detail property. Then you find the illuminating cause of the error:

SoapException.Details: < errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Cannot complete this action. Please try again.< /errorstring>< errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x80004005< /errorcode>

After several random guesses, I tripped over the fact that you need to format your criteria into pairwise conditions, like this:


< where>< and>
< /and>< and>
< eq>< fieldref Name="Group_x0020_ID" />< value Type="Text">0109001001< /value>< /eq>
< eq>< fieldref Name="Plan_x0020_ID" />< value Type="Text">RNR01A< /value>< /eq>
< /and>
< and>
< eq>< fieldref Name="Document_x0020_Type" />< value Type="Text">SMM< /value>< /eq>
< gt>< fieldref Name="Effective_x0020_Date" />< value Type="DateTime">2/16/1992 12:15:12< /value>< /gt>
< /and>
< /where>

Wouldn’t it be great if you just told me that; instead of only hinting at it through the examples?

But you’re not out of the woods yet. Now, the system returns ALL the list items, ignoring the criteria. According to a discussion on www.codecomments.com (which is dead in the water at the time of this writing), the service straight-up DOES NOT SUPPORT DATE QUERIES. Oh there’s more. Despite all the examples, despite my contorting the XML to avoid that exception, I never got this query to work. Instead of getting only the list items I was asking for, it stubbornly kept returing ALL the list items. Once I trimmed it town to two text-only criteria, I started getting the right results. But then I hear you say, “Jesse, you must have done something wrong. The examples never lie.” However, consider the fact that only two criteria are permitted when configuring a SharePoint view. Also, consider that Serge can’t get ANY criteria to work, and uses the DSTS web service instead. Given that coincidence, the previous two bald-faced lies, and other people’s pain, I’m given to think this only-two-criteria is more than just my fat-fingers or bad data.

So, I call out to all you techy types. Can you do more than I? Have you been able to run a Lists.asmx query with more than two criteria? The challenge is on.

Leave a Reply