2 minute read
I was trying to track down some odd behavior in SharePoint’s Lists Web Service tonight, and I think I’ve found what I can only call a bug.
Here’s the scenario. All of these conditions must apply::
- Using the GetListItems operation
- Querying a list which has a required multi-select column
- Specifying columns to return in the ViewFields parameter (whether or not the multi-select column above is specified)
- The multi-select column has more than one value selected in an item (or items)
In this specific case, there are multiple copies of each item returned, one per value which is set in the required multi-select column.
I found two other posts on the Interwebs about this. In both cases, the writer found the same problem, but was unable to determine the reason or a fix:
- Andy Burns’ SharePoint Blog: Why I was getting duplicate rows from the SharePoint Lists Web service
- Egghead Cafe forums: Lists.GetListItems web service bug
Both posts are from 2008, so I’m sure these guys have long since moved on, though I did leave Andy a comment.
It looks like a fix which will work is to not specify the columns in ViewFields. This will make the GetListItems calls less efficient, of course, but it will make them work correctly.
The other solution, which doesn’t really make any sense, is to include
FALSE doesn’t do what it it is supposed to do per the SDK, but in this case it serves a useful purpose by eliminating the duplicate items. I worry when I find these seemingly kludgy fixes, but it is *extremely* unlikely that the Web Services are going to change, so I use them anyway. Even if
IncludeMandatoryColumns suddenly started doing what it should, I’d be fine here (and the calls to GetListItems would be even *more* efficient.)
Any other ideas out there?
Here’s an example. There’s only one item in the States list for Massachusetts. There’s a column called Staff, which is a Person or Group, allows multiple selections, and is required:
In my call to GetListItems, I’m specifying the two columns I would like returned:
CAMLViewFields: "<ViewFields><FieldRef Name='" + opt.relationshipListParentColumn + "' /><FieldRef Name='" + opt.relationshipListChildColumn + "' /></ViewFields>",
GetListItems returns a copy of the item per value for Staff. Note that the Staff column is being returned, even though i am *not* requesting it. (I’m only requesting the Region and State [Title] columns, but the other columns besides Staff come back regardless. Not exactly what I asked for, but it seems to be intentional in all of my experience with GetListItems. They are sort of the “base” columns which you’d need to do anything useful with the items.)