Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm having some trouble getting a CAML Query working against a very simple list.

My custom list has the fields:

  • Person : User
  • Date : Date
  • Amount : Lookup

My query looks like this:

<Query>
  <Where>
    <Eq>
      <FieldRef Name='Person' LookupId='TRUE' />
      <Value Type='Integer'>{0}</Value>
    </Eq>
  </Where>
</Query>

and {0} contains an integer.

Problem

My list contains 8 elements, divided between two seperate users. My query is supposed to get me 4 elements back, but is always returning 8.

I have been researching this for quite some time now (using both U2U Query Builder, and trying to handwrite it) but have been unable to get it to filter.

Please advise!

Solution

The solution was to remove the <Query></Query> from the CAML Query-string. The below accepted answer doesn't adress this, though it is also correct.

share|improve this question
    
Did you have a look at this question: sharepoint.stackexchange.com/questions/29079/… ? And: Does the filtering work in the U2U Query Builder? –  Dribbel May 11 '12 at 9:42
1  
Remove <Query></Query>, see if it helps –  tarjeieo May 11 '12 at 9:48
add comment

1 Answer

up vote 5 down vote accepted

Try to use this caml:

<Where>
  <Eq>
    <FieldRef Name="Author" LookupId="True" />
    <Value Type="User">123</Value>
  </Eq>
</Where>

this also might work, but first is preferable:

<Where>
  <Eq>
    <FieldRef Name="Author" LookupId="True" />
    <Value Type="Lookup">123</Value>
  </Eq>
</Where>

and also, if you want to pass current logged user into caml query, you can use this one:

<Where>
  <Eq>
    <FieldRef Name="Author" />
    <Value Type="Integer">
      <UserID />
    </Value>
  </Eq>
</Where>
share|improve this answer
1  
Nice tip there on the last one, didn't know that. –  PirateEric May 11 '12 at 12:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.