I want to retrive some fields with CAML Query - everytime when i execute query for example:
query.ViewXml = string.Format(@"
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='IDCardNumber' LookupId='TRUE'/>
<Value Type='Text'>12345</Value>
</Eq>
</Where>
</Query>
</View>
< ViewFields >
< FieldRef Name = 'Title' />
</ ViewFields >)");
var items = list.GetItems(query);
clientContext.Load(items);
clientContext.ExecuteQuery();
Query returns 0 elements.
I tried to get all elements and with CamlQuery.CreateAllItemsQuery();
- and in date I see correct count in list data, but FieldValues in elements look like this: Screenshot from VS Locals
In CAML Query Builder Tool:
<Where>
<IsNotNull>
<FieldRef Name='Title' />
</IsNotNull>
</Where>
</Query>
Returns: Screenshot from CAML Query Builder
How to get these values correctly?
I think the value type should be "Lookup" then your using the id of the lookup field (ie the id of the field in the alternative list)
<Eq>
<FieldRef Name='IDCardNumber' LookupId='TRUE'/>
<Value Type='Lookup'>12345</Value>
</Eq>
ViewFields goes in View
query.ViewXml = @"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='IDCardNumber' LookupId='TRUE'/>
<Value Type='Lookup'>12345</Value>
</Eq>
</Where>
</Query>
<ViewFields>
<FieldRef Name = 'Title'/>
<FieldRef Name = 'IDCardNumber'/>
</ViewFields>
</View>
";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.