0

I'm having problems working with collections. I want to eliminate some entries from a collection based on the contents of another collection.

I have two collections; one holds a set of workflow tasks I have obtained via SPQuery (SPListItemCollection) and the other is a list of users from a people picker (SPFieldUserValueCollection).

I want to get a list (of type SPFieldUserValueCollection) which contains only those users who have not been assigned the workflow task listed in the query.

Short of iterating through the list of users, and comparing the LookupID with the "Assigned To" field on the workflow task (which I really don't want to do), how can this best be done?

I'm looking for an elegant solution.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335

1 Answers1

1

Another possibility would be to query the user-list with an SPQuery too. That would be much faster than iterating through all users. You could use the <In> Tag inside the query to get all users that have not been assigned by a workflow. For this tag check: http://rmanimaran.wordpress.com/2011/03/11/new-in-sharepoint-2010-caml-query/

An example on how to exclude items from the page:

<Where>     
    <And>     
        <Eq>     
            <FieldRef Name="Specialization"/>     
            <Value Type="Lookup">SQL Server</Value>     
        </Eq>     
        <NotIncludes>     
            <FieldRef Name='Specialization'/>     
            <Value Type='Lookup'>Crystal Report</Value>     
        </NotIncludes>     
     </And>     
</Where>
RononDex
  • 4,143
  • 22
  • 39
  • Sorry, but I don't see how this helps. Perhaps I am ignorant here but I don't see a way to define a CAML query which will exclude items based on a separate column. –  Dec 02 '13 at 14:34
  • You have asked for alternatives or more elegant ways on how to exclude data from a specific sharepoint-listitemcollection from another sharepoint-listitemcollection right? If not then I misunderstood your question and you might consider writing it in a more "easier" way... – RononDex Dec 02 '13 at 14:37
  • It will help you in terms of performance. Your application will run much faster on large sharepoint-sites with a huge amount of users when doing it with CAML query instead of interating through SPList.Items. That makes it a more elegant way in my opinion – RononDex Dec 02 '13 at 14:39
  • I agree that using CAML would be a lot faster and this would be my preferred option. –  Dec 02 '13 at 14:54
  • I've thought about this and it makes more sense now. But I still don't see how to get the user-list into the CAML query. From there I can see how you would then you would use AND NOTINCLUDES to exclude the other entries. –  Dec 02 '13 at 15:13
  • You have to do something like this (pseudocode): `foreach (var workflow in workflows) { notIncldues += "" + workflow["AssignedUser"].ToString() + ""; }` – RononDex Dec 02 '13 at 15:16
  • Perhaps we are at cross-purposes. I already have the set of users who have been assigned the workflow in question (from entries in "Workflow Tasks"). This set was obtained using CAML - we will call this "Set A". I also already have a set of users from my people picker. We will call this "Set B". I would like to insert these user IDs into a CAML query (for the NOTINCLUDES clause) but I need some list to run the query against, correct? Just to be clear, I need to obtain the set(B-A). –  Dec 03 '13 at 08:37
  • The userlist is a normal SPList. If you iterate through SPWeb.Lists you should find it. You can select the same users like in the people picker with a CAML query and combinde with `...` – RononDex Dec 03 '13 at 09:24
  • That's the piece of the puzzle I was missing. Thanks! –  Dec 03 '13 at 10:19