Skip to main content
replaced http://sharepoint.stackexchange.com/ with https://sharepoint.stackexchange.com/
Source Link

Based on feedback from my earlier questionearlier question, I have constructed a query using the excellent CAML Builder tool:

<Where>
<Or>
  <Membership Type='CurrentUserGroups'>
    <FieldRef Name='Users'/>
 </Membership>
 <Eq>
  <FieldRef Name='Users'/>
  <Value Type='Integer'>
    <UserID/>
  </Value>
 </Eq>
</Or>
</Where>

This indeed returns a filtered list of rows.

However, trying to implement the same query in code fails to filter the list (all items are returned):

     SPQuery query = new SPQuery();
     query.Query =
        "<Where><Or><Membership Type='CurrentUserGroups'><FieldRef Name='Users'/></Membership>" +
        "<Eq><FieldRef Name='Users'/><Value Type='Integer'><UserID /></Value></Eq></Or></Where>";
     var items = spList.GetItems(query);

I have attempted to use the ViewXml property instead, but no success either.

EDIT: I have removed the enclosing <Query> tags as suggested, but now rather than returning all items, the query now return no items at all!

Based on feedback from my earlier question, I have constructed a query using the excellent CAML Builder tool:

<Where>
<Or>
  <Membership Type='CurrentUserGroups'>
    <FieldRef Name='Users'/>
 </Membership>
 <Eq>
  <FieldRef Name='Users'/>
  <Value Type='Integer'>
    <UserID/>
  </Value>
 </Eq>
</Or>
</Where>

This indeed returns a filtered list of rows.

However, trying to implement the same query in code fails to filter the list (all items are returned):

     SPQuery query = new SPQuery();
     query.Query =
        "<Where><Or><Membership Type='CurrentUserGroups'><FieldRef Name='Users'/></Membership>" +
        "<Eq><FieldRef Name='Users'/><Value Type='Integer'><UserID /></Value></Eq></Or></Where>";
     var items = spList.GetItems(query);

I have attempted to use the ViewXml property instead, but no success either.

EDIT: I have removed the enclosing <Query> tags as suggested, but now rather than returning all items, the query now return no items at all!

Based on feedback from my earlier question, I have constructed a query using the excellent CAML Builder tool:

<Where>
<Or>
  <Membership Type='CurrentUserGroups'>
    <FieldRef Name='Users'/>
 </Membership>
 <Eq>
  <FieldRef Name='Users'/>
  <Value Type='Integer'>
    <UserID/>
  </Value>
 </Eq>
</Or>
</Where>

This indeed returns a filtered list of rows.

However, trying to implement the same query in code fails to filter the list (all items are returned):

     SPQuery query = new SPQuery();
     query.Query =
        "<Where><Or><Membership Type='CurrentUserGroups'><FieldRef Name='Users'/></Membership>" +
        "<Eq><FieldRef Name='Users'/><Value Type='Integer'><UserID /></Value></Eq></Or></Where>";
     var items = spList.GetItems(query);

I have attempted to use the ViewXml property instead, but no success either.

EDIT: I have removed the enclosing <Query> tags as suggested, but now rather than returning all items, the query now return no items at all!

Tweeted twitter.com/#!/StackSharePoint/status/259399236666408960
Removed <Query> return no items at all
Source Link
Philipp Schmid
  • 383
  • 1
  • 3
  • 14

Based on feedback from my [earlier question][1]earlier question, I have constructed a query using the excellent CAML Builder tool:

<Where>
<Or>
  <Membership Type='CurrentUserGroups'>
    <FieldRef Name='Users'/>
 </Membership>
 <Eq>
  <FieldRef Name='Users'/>
  <Value Type='Integer'>
    <UserID/>
  </Value>
 </Eq>
</Or>
</Where>

This indeed returns a filtered list of rows.

However, trying to implement the same query in code fails to filter the list (all items are returned):

     SPQuery query = new SPQuery();
     query.Query =
        "<Query><Where><Or><Membership"<Where><Or><Membership Type='CurrentUserGroups'><FieldRef Name='Users'/></Membership>" +
        "<Eq><FieldRef Name='Users'/><Value Type='Integer'><UserID /></Value></Eq></Or></Where></Query>";Where>";
     var items = spList.GetItems(query);

I have attempted to use the ViewXml property instead, but no success either. [1]:

EDIT: I have Filter People and Group column using [Me]removed the enclosing <Query> tags as suggested, but now rather than returning all items, the query now return no items at all!

Based on feedback from my [earlier question][1], I have constructed a query using the excellent CAML Builder tool:

<Where>
<Or>
  <Membership Type='CurrentUserGroups'>
    <FieldRef Name='Users'/>
 </Membership>
 <Eq>
  <FieldRef Name='Users'/>
  <Value Type='Integer'>
    <UserID/>
  </Value>
 </Eq>
</Or>
</Where>

This indeed returns a filtered list of rows.

However, trying to implement the same query in code fails to filter the list (all items are returned):

     SPQuery query = new SPQuery();
     query.Query =
        "<Query><Where><Or><Membership Type='CurrentUserGroups'><FieldRef Name='Users'/></Membership>" +
        "<Eq><FieldRef Name='Users'/><Value Type='Integer'><UserID /></Value></Eq></Or></Where></Query>";
     var items = spList.GetItems(query);

I have attempted to use the ViewXml property instead, but no success either. [1]: Filter People and Group column using [Me]

Based on feedback from my earlier question, I have constructed a query using the excellent CAML Builder tool:

<Where>
<Or>
  <Membership Type='CurrentUserGroups'>
    <FieldRef Name='Users'/>
 </Membership>
 <Eq>
  <FieldRef Name='Users'/>
  <Value Type='Integer'>
    <UserID/>
  </Value>
 </Eq>
</Or>
</Where>

This indeed returns a filtered list of rows.

However, trying to implement the same query in code fails to filter the list (all items are returned):

     SPQuery query = new SPQuery();
     query.Query =
        "<Where><Or><Membership Type='CurrentUserGroups'><FieldRef Name='Users'/></Membership>" +
        "<Eq><FieldRef Name='Users'/><Value Type='Integer'><UserID /></Value></Eq></Or></Where>";
     var items = spList.GetItems(query);

I have attempted to use the ViewXml property instead, but no success either.

EDIT: I have removed the enclosing <Query> tags as suggested, but now rather than returning all items, the query now return no items at all!

Source Link
Philipp Schmid
  • 383
  • 1
  • 3
  • 14

CAML Query behaving differently in CAML Builder and Code

Based on feedback from my [earlier question][1], I have constructed a query using the excellent CAML Builder tool:

<Where>
<Or>
  <Membership Type='CurrentUserGroups'>
    <FieldRef Name='Users'/>
 </Membership>
 <Eq>
  <FieldRef Name='Users'/>
  <Value Type='Integer'>
    <UserID/>
  </Value>
 </Eq>
</Or>
</Where>

This indeed returns a filtered list of rows.

However, trying to implement the same query in code fails to filter the list (all items are returned):

     SPQuery query = new SPQuery();
     query.Query =
        "<Query><Where><Or><Membership Type='CurrentUserGroups'><FieldRef Name='Users'/></Membership>" +
        "<Eq><FieldRef Name='Users'/><Value Type='Integer'><UserID /></Value></Eq></Or></Where></Query>";
     var items = spList.GetItems(query);

I have attempted to use the ViewXml property instead, but no success either. [1]: Filter People and Group column using [Me]