Query Criteria on a Lookup Field

Dec 7, 2012 at 1:53 PM

I've spent about two hours trying to get this to work...no 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 function...it'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"...to no avail.   I've also tried using a var to hold the criteria...no worky.  I've tried LookupId='False' and using the number 3 as criteria...no luck.

Thanks,

Don

 

Coordinator
Dec 7, 2012 at 2:00 PM

Have you tried:

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

M.

Dec 7, 2012 at 2: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 2: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 3:03 PM

 

Can you past your entire code showing the GetListItem call?

Dec 7, 2012 at 3: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.

Cheers,
Matthew 

Dec 7, 2012 at 7: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!

Don

Dec 7, 2012 at 9:25 PM

Don,
Glad to hear you got it working ...

Paul

Sent from mobile

Dec 10, 2012 at 5: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?

Don

Coordinator
Dec 10, 2012 at 7:30 PM

Don:

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

<And>
  <Or>
    something
    something else
  </Or>
  yet another something
</And>

M.

Dec 10, 2012 at 8:08 PM

Thanks Marc.  I just had to nest Ors.