Learning: caml-query lookup field by ID; not by value

Source: Internet
Author: User

When lookup fields are created, Sharepoint stores them
ID; # value format in related list.

For e.g.
In list "contacts" there is column called "country ".
There is item in contact with value "India" assigned in country, having item id = 10.

Now for another list "list2" when column "country" is stored as lookup column named "refcountry"; and for certain data item "India" is selected from combo box, sharePoint stores it in,

10; # India in "List 2"-> "refcountry" column.

When having caml query in list2

The typical query looks like
<Query>
<Where>
<EQ>
<Fieldref name = "refcountry"/>
<Value type = "lookup"> India </value>
</EQ>
</Where>
</Query>

The disadvantage of this way is if list contacts is having more than one entry (item or row) having value India for countryIt will return the only first one.This may give inconsistent data for further.

To avoid this query shocould be base on id not by value.
This can be achieved thru:

<Query>
<Where>
<EQ>
<Fieldref name = "refcountry" lookupid = "true"/>
<Fieldref name = "refcountry" lookupid = "true"/>
<Value type = "lookup"> 10 </value>
</EQ>
</Where>
</Query>

Where 10 is the ID for item having Country = "India"

 

Come from: http://abstractspaces.wordpress.com/2008/05/05/caml-query-lookup-field-by-id-not-by-value/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.