Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm having trouble using the Join via Caml. In a way, I'm having trouble working with 1 field, that is "new window" that the field type is boolean.

My code looks like this:

SPQuery oQuery = new SPQuery();
StringBuilder sbJoin = new StringBuilder();
StringBuilder sbProj = new StringBuilder();
StringBuilder sbQuery = new StringBuilder();

using (SPSite siteCollection = new SPSite("http://localhost/"))
{
    using (SPWeb web = siteCollection.OpenWeb())
    {
        SPList oList = web.Lists["shortcuts users"];
        SPListItemCollection items = null;

        sbJoin.Append("<Join Type='INNER' ListAlias='shortcuts'>");
        sbJoin.Append("<Eq>");
        sbJoin.Append("<FieldRef Name='shortcut' RefType='Id'/><FieldRef List='shortcuts' Name='ID'/>");
        sbJoin.Append("</Eq>");
        sbJoin.Append("</Join>");

        sbQuery.Append("<Where>");
        sbQuery.Append("<Eq><FieldRef Name='user' /><Value Type='Number'>1</Value></Eq>");
        sbQuery.Append("</Where>");
        sbQuery.Append("<OrderBy><FieldRef Name='order' Ascending='True' /></OrderBy>");

        sbProj.Append("<Field Name='shortcutName' Type='Lookup' List='Atalhos' ShowField='Title'/>");
        sbProj.Append("<Field Name='shortcutLink' Type='Lookup' List='Atalhos' ShowField='link'/>");
        sbProj.Append("<Field Name='shortcutNewWindow' Type='Boolean' List='Atalhos' ShowField='newWindow'/>");
        sbProj.Append("<Field Name='AtalhoContentTypeId' Type='Lookup' List='Atalhos' ShowField='ContentTypeId' />");

        oQuery.ViewFields = "<FieldRef Name='Title'/><FieldRef Name='order'/><FieldRef Name='shortcutName'/><FieldRef Name='shortcutLink'/><FieldRef Name='shortcutNewWindow'/>";
        oQuery.Joins = sbJoin.ToString();
        oQuery.Query = sbQuery.ToString();
        oQuery.ProjectedFields = sbProj.ToString();

        items = oList.GetItems(oQuery);

        if (items.Count > 0)
        {
            foreach (SPListItem item in items)
            {
                Console.WriteLine("Name: {0}, order: {1} - shortcut Name: {2}, shortcut Link: {3} shortcut New Window: {4}",
                        item["Title"],
                        item["order"],
                        item["shortcutName"],
                        item["shortcutLink"],
                        item["shortcutNewWindow"]);
            }

            Console.WriteLine("Total: {0}", items.Count);
        }
    }
}

Console.ReadLine();

The problem is in this line:

sbProj.Append("<Field Name='shortcutNewWindow' Type='Boolean' List='Atalhos' ShowField='newWindow'/>");

If I use the boolean type of the field as it returns this error: 0x80070057

Now if I use the field type as another Lookup returns this error: Value does not fall within the expected range

What type of field, I have to use in order to function?

share|improve this question
add comment

1 Answer

The ListAlias in the Join clause should be the same as the List of your projected fields.

Similar error

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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