Answered Is it possible to query list with type People or Group?

  • Monday, August 20, 2012 6:42 AM
     
     

    Hi

    Is it possible to query list with type People or Group?


All Replies

  • Monday, August 20, 2012 9:34 PM
     
     
    Hello wapt49, could you provide an example of the query you are trying to achieve? Something like "give me all the items assigned to person X?"
  • Tuesday, August 21, 2012 1:06 PM
     
     

    Hello Humberto,

    For example I have 3 kinds of users groups within a project (marketing, HRD and developers). I want to limit the results of a list based on the person who is logged on (based on group membership). So if I logged in as John and John was assigned to group marketing then I need to query something like

    1. "Give me the group assigned to John"

    -> The result is marketing

    2. "Give me all the items assigned to group marketing"

    -> Then i will get the item list for group marketing

    Please let me know if something unclear :)

  • Tuesday, August 21, 2012 5:41 PM
     
     
    Got it. Are you using the SharePoint 2013 preview? I was going to poke some folks for more info and potentially get a sample but if you are using SharePoint 2010 then the sample might not help you
  • Tuesday, August 21, 2012 6:01 PM
     
     

    Unfortunately I am using Sharepoint 2010. Is not possible to query as I described above using Sharepoint 2010?

  • Tuesday, August 21, 2012 7:49 PM
     
     

    There are probably a couple of ways using CAML + the Object model but I'm not an expert on previous versions. I'll move your post to a forum that might yield you better results. Thanks.

  • Wednesday, August 22, 2012 6:10 AM
    Moderator
     
     Answered

    Hi wapt49,

    To query with people and group field in SharePoint list, you can format the query string like this:
    <Where><Eq><FieldRef Name='Person' LookupId='TRUE'/><Value Type='Int'>" + userId + "</Value></Eq></Where><//span>

    You can also get more information about this from following links:
    http://www.stum.de/2008/02/06/querying-the-person-or-group-field-using-spquery/
    http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/15b976de-567f-4383-bbe5-d4fb84375893

    Thanks,


    Qiao Wei

    TechNet Community Support

  • Wednesday, August 22, 2012 6:35 AM
    Answerer
     
     Answered Has Code

    Hello,

    I found this topic :http://sympmarc.com/2010/06/16/caml-filter-for-current-group-membership/

    it seems that you can get item assigned to user and to his group with this query

    <Or>
     <Membership Type=\"CurrentUserGroups\">
        <FieldRef Name=\"AssignedTo\"/>
      </Membership>
      <Eq>
        <FieldRef Name=\"AssignedTo\"></FieldRef>
        <Value Type=\"Integer\">
          <UserID/>
        </Value>
      </Eq>
    </Or>
    


    Best regards, Christopher.
    Blog | Mail
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

  • Friday, August 31, 2012 10:27 AM
     
     

    Hi,

    Thanks all for the reply. I am sorry just reply it yet.

    However this is my real case example :

    Let say I have user : Putra.

    Putra has 2 groups: 1. tes, 2. developer.

    I have also a list below ( I have mutiple values in group column)

    So when I logged on as Putra, I only want display : Marissa, Ulfa and Agy in the list.

    Because Dara doesnt have Group which Putra has (tes and Developer).

    Can anyone help me to solve my issue? What should CAML Query looks like? or maybe can we solve this issue using LINQ?

    Many Thanks :)