1

My project uses the 2010 version of the Sharepoint Filtered Lookup Field, which has the option to filter a column using a caml query.

So I have three lists: Categories, SubCategories and MainList.

Categories is just a plain list.

SubCategories is a list with two columns: Title and Category where Category is a regular lookup column leading to the Categories list.

MainList has a column for Category and for SubCategory - but SubCategory is supposed to filter on Category.

So I want to write a CAML query that filters the SubCategories list. It should show only those SubCategories where [Title] is equal to the Category.

<Query>
    <Where>
        <Eq>
            <FieldRef Name="Category"/>
            <Value Type="Text">[Title]</Value>
        </Eq>
    </Where>
    <OrderBy>
        <FieldRef Name="Title" />
    </OrderBy>  
</Query>        
0

2 Answers 2

3

Let's try like this:

<Query>
    <Where>
        <Eq>
            <FieldRef Name="Category"/>
            <Value Type="Lookup">[Title]</Value>
        </Eq>
    </Where>
    <OrderBy>
        <FieldRef Name="Title" />
    </OrderBy>  
</Query>  

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

Ruslan Dayanov

2
  • It seems you have missed something from the question. OP needs to compare two columns of the list. Generally CAML can compare columns with some values! Commented Nov 28, 2015 at 6:58
  • No, I think he is right; problem is that he assumed what I assumed, that the addon would allow for the current variable to be inserted. See my answer where I have found out it doesn't work that way.
    – bgmCoder
    Commented Nov 28, 2015 at 21:22
0

Ah, as it turns out, this cannot be done with the FilteredLookup addon. You cannot add the current value into the query via variables, which is what I expected you could do with the [Title] code in my example.

Here is where the authour says it doesn't work that way.

This is too bad; it would make for wonderful functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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