12

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?

  • Do you want to query multiple items by lookup value? – Ruslan Dayanov Oct 26 '14 at 9:13
  • its straight forward query. what you want to acheive? – SharePointMan Oct 26 '14 at 16:44
  • So I want to query multiple items by lookup value? How can i do it? – f_gulay Sep 28 '17 at 15:46
20

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

  • 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> – Michal Hainc Feb 9 '18 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.