14

I have the value of a lookup column, but I don't have the ID, I want to query items from SharePoint list using the lookup value. How do I achieve that in CAML?

3
  • Do you want to query multiple items by lookup value? Oct 26, 2014 at 9:13
  • its straight forward query. what you want to acheive? Oct 26, 2014 at 16:44
  • So I want to query multiple items by lookup value? How can i do it?
    – f_gulay
    Sep 28, 2017 at 15:46

1 Answer 1

27

Default lookup query uses the value instead of lookup Id

The typical query looks like

<Query>
    <Where>
        <Eq>
            <FieldRef Name='RefCountry'  />
            <Value Type='Lookup'>India</Value>
        </Eq>
    </Where>
</Query>

To query by ID you have o setup LookupId='TRUE' attribute of FieldRef element

<FieldRef Name='RefCountry' LookupId='TRUE' />

http://msdn.microsoft.com/en-us/library/office/ms442728(v=office.15).aspx

1
  • How would I achieve that with "IN" clause? e.g. this doesn't work: <View Scope="RecursiveAll"> <Query> <Where> <In> <FieldRef Name="FileRef" /> <Values> <Value Type="Lookup"><![CDATA[/sites/site1/Shared Documents/abc.png]]></Value> </Values> </In> </Where> </Query> <ViewFields> <FieldRef Name="ID" /> <FieldRef Name="FileRef" /> <FieldRef Name="Author" /> <FieldRef Name="Editor" /> </ViewFields> <RowLimit Paged="TRUE">100</RowLimit> </View>
    – michalh
    Feb 9, 2018 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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