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 DayanovOct 26, 2014 at 9:13
-
its straight forward query. what you want to acheive?– SharePointManOct 26, 2014 at 16:44
-
So I want to query multiple items by lookup value? How can i do it?– f_gulaySep 28, 2017 at 15:46
1 Answer
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>– michalhFeb 9, 2018 at 10:07