This project has moved and is read-only. For the latest updates, please go here.

Query Criteria on a Lookup Field

Dec 7, 2012 at 2:53 PM

I've spent about two hours trying to get this to luck yet...need help please! 

The value I'm looking for is "3 - Planning" in the CurrentPhase lookup field. 

Here is my CAMLQuery: (I can't use the paste code's blocked by my network)

...inside the "Where" tags: <FieldRef Name='CurrentPhase' LookupId='True' /><Value Type='Lookup'>3 - Planning</Value>

Returns no records.  I've tried LookupId True/False to no avail.  I've tried formatting the criteria the way it's returned in a recordset - "3;#3 - Planning" no avail.   I've also tried using a var to hold the worky.  I've tried LookupId='False' and using the number 3 as luck.




Dec 7, 2012 at 3:00 PM

Have you tried:

<FieldRef Name='CurrentPhase' /><Value Type='Text'>3 - Planning</Value>


Dec 7, 2012 at 3:08 PM

Or (to add to Marc's suggestion), have you tried:

<FieldRef Name='CurrentPhase' LookupId='True'/><Value Type='Lookup'>3</Value>

Assuming that the item '3 - Planning' is actually the record with ID = 3.
Paul T

Dec 7, 2012 at 3:51 PM

Thanks for the suggestions.  Neither of those works.  The call is otherwise working, as I can remove the CAMLQuery string and it returns all records. 

The CurrentPhase field returns "3;#3 - Planning"....regardless of whether I set the CAMLViewFields FieldRef to "LookupId='True'" or not. 


Dec 7, 2012 at 4:03 PM


Can you past your entire code showing the GetListItem call?

Dec 7, 2012 at 4:56 PM

You wouldn't set the CAMLViewFields to have a "LookupId='True'" attribute.  You would put that in the CAMLQuery however.  Paste your code when you have a second and I'm sure we can get you fixed up.


Dec 7, 2012 at 8:36 PM

iOnline...I was just playing with the LookupId argument, I realized it didn't do anything to the returned values. 

I DID get the query criteria to work:  I left out the <Eq></Eq> tags!   It's always something stupid!

ptavares...I can't paste the code block from work, because my network nazis have that functionality blocked.  I'm sure if I posted it, you would have spotted the missing tags.   Your example above is what worked...LookupId='True' and using the ID from the lookup list (3) for the value.  

Thanks Guys!


Dec 7, 2012 at 10:25 PM

Glad to hear you got it working ...


Sent from mobile

Dec 10, 2012 at 6:45 PM

One more problem:

I have two sets of <Eq></Eq> criteria between <Or></Or>.  When I try to add a third <Eq></Eq> criteria between the Or tags, it stops pulling records.   Can I have more than 2 criteria in the Or tags?


Dec 10, 2012 at 8:30 PM


Check out the CAML references. CAML uses a sort of odd sideways notation. you can only have two conditions surrounded by a conjunction. Example:

    something else
  yet another something


Dec 10, 2012 at 9:08 PM

Thanks Marc.  I just had to nest Ors.