Why I was getting duplicate rows from the SharePoint Lists Web service

A couple of months ago I was making some calls to the SharePoint Lists Web Service, and I found that I was getting the same item back multiple times. This puzzled me – I mean, it was clearly by design, but why would anyone want a copy of the item for each value selected in a multiple-selection lookup?

It hit me last weekend (like a bolt from the blue) – you could use this to support Group By clauses on queries on a list. Yes, I know, SharePoint itself doesn’t support this functionality, but you could use the behaviour that I’d seen to support this. It’s the only explanation I’ve found that makes sense.

Now, can you turn off this behaviour, so you only get one item. That would be a lot more useful for what I was trying to do, although I now get why you might want that behaviour. Well, I don’t see a query option for it in the documentation, and cracking the service open in Lutz Reflector doesn’t show an option for it either.

I guess we’ll just have to accept the GetListItems command in the Web service API supporting Group By functionality, while SharePoint’s user interface itself does not. It’s a bit weird though that there isn’t an option I can find to turn it off though, and the Object Model behaves quite differently – it only returns one ListItem, and is unaffected by the multi-select lookup.

Advertisements
Why I was getting duplicate rows from the SharePoint Lists Web service

5 thoughts on “Why I was getting duplicate rows from the SharePoint Lists Web service

  1. Andy:

    I know that this is an old post, but I just ran across it while researching the exact same behavior as I’m working on SPServices.

    In my testing, I find that if I *don’t* specify the ViewFields, I don’t get the duplicate items. I think it’ll probably solve things for me, but I’m still puzzled by why this works the way it does.

    I’d appreciate it if you could let me know if you ever found out more…

    M.

  2. Hi Marc,

    Yeah, me too – I don’t get why it works that way. I didn’t try without the ViewFields, if I remember rightly.

    I meant to try (and never did) a list with multiple multi-select columns. I wondered if combinatorial explosion was a possible issue.

    But nope, that was the last I found out about it. One of those “Weird, but I have to get it working” type of problems.

  3. I appreciate your posts on this topic, I ran into the very same issue although a bit later than you, I found the if you call getList first, iterate through the fields in the list definition adding the “req’d” ones (those with Type=”LookupMulti”) to avoid duplicates, plus the items you really wanted everything is ok. Note potentially a new option admins can set a limit to the max number of fields to retrieve. So something that worked previously may not work under 2010. e.g. retrieve all fields from the list def and use those to build a viewfields.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.