Question

Hello Sharepoint developers !

Have you ever tried to do a join between lists and in both of those lists needed to place a where clause? I can do it in the first list, but can't find out how to place the where in the foreign list.

I tried several solutions like this one :

using (SPWeb web = sps.OpenWeb())
            {
                SPList spl = web.GetList(customers);
                SPQuery query = new SPQuery();
                query.Query = "<Where><Eq><FieldRef Name='Suspended'/><Value Type='Boolean'>0</Value></Eq></Where>";
               query.Joins=@"<Join Type='Inner' ListAlias='CountryList'><And><Eq><FieldRef Name='Country' RefType='Id'/><FieldRef List='CountryList' Name='ID'/></Eq><Eq><FieldRef List='CountryList' Name='Continent' /><Value Type='Text'>Europe</Value></Eq>
                        </And></Join>";
                ....

But this is not working. I want to get all not suspended customers coming from all towns (another list) in Europe. So I need a where in the primary list (spl) to get not suspended customers and a where in the foreign list to get towns from europe only. I can't place my where in the Join element aparently. I tried to place it in the query, giving the list alias but it's not working either.

would you have an idea ? thanks !

Was it helpful?

Solution

Use a calculated column that translates the boolean value to text.

OTHER TIPS

Ok I found my answer :

You can add a where clause even on the foreign list, but the targeted field can't be a Boolean :( because there are supported types (ProjectedFields). Actually if you want to filter the foreign list on its specific field, you might wanna declare it in the projected fields element so that they are recognized in your where clause in the Query property of SPQuery.

For example, in the previous case,

 SPList spl = web.GetList(customers);
            SPQuery query = new SPQuery();
            query.Query = @"<Where><And>
<Eq><FieldRef Name='Suspended'/><Value Type='Boolean'>0</Value></Eq>
<Eq><FieldRef Name='ContinentCountryList' List="CountryList"/><Value Type='Text'>Europe</Value></Eq>
</And></Where>";
               query.Joins=@"<Join Type='Inner' ListAlias='CountryList'><Eq><FieldRef Name='Country' RefType='Id'/><FieldRef List='CountryList' Name='ID'/></Eq>
                     </Join>";
    query.ProjectedFields = "<Field Name='ContinentCountryList' Type='Lookup' List='CountryList' ShowField='Continent'/>

Now this is working I'll get not suspended customers from towns in Europe only. So I must reference my foreign field in the projectedFields element. But it's only working with types listed above in the msdn link...

too bad for me it was a boolean, I guess I must deal with temporary lists in memory unless you have any other suggestions...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top