Pregunta

I am trying to query all Tasks throughout my site collection using the following where clause in my CAML Query. From what I can tell this code is exactly as specified in this presumably reliable blog entry. Anyone know why it would not work? Thanks for reading

My code won't even execute as it complains about my CAML Query

"<Where>" +

     "<And>" +
         "<BeginsWith>" +
              "<FieldRef Name=\"ContentTypeId\" />" +
              "<Value Type=\"ContentTypeId\">0x0108009D937E40833C472CBC11D246C635B662</Value>" +
         "</BeginsWith>" +

          "<Eq>" +
               "<FieldRef Name=\"TaskStatus\" />" +
               "<Value Type=\"Text\">Completed</Value>" +
          "</Eq>" +


          "<Eq>" +
                "<FieldRef Name=\"AssignedTo\" />" +
                 "<Value Type=\"Lookup\">" + id + "</Value>" +
          "</Eq>" +

          "</And>" +

          "</Where>" +

            "<OrderBy>" +
                 "<FieldRef Name=\"Title\"/>" +
            "</OrderBy>";
¿Fue útil?

Solución

I agree with the above answer. Since there are multiple And elements here, and any And element supports only 2 conjuncts, nested And elements must be used to conjoin multiple conditions. If you are using the default Task List in SharePoint, try the following CAML Query-

<Query>
    <Where>
        <And>
            <BeginsWith>
                <FieldRef Name="ContentTypeId" />
                <Value Type="Counter">0x0108009D937E40833C472CBC11D246C635B662</Value>
            </BeginsWith>
            <And>
                <Eq>
                    <FieldRef Name="TaskStatus" />
                    <Value Type="Choice">Completed</Value>
                </Eq>
                <Eq>
                    <FieldRef Name="AssignedTo" />
                    <Value Type="UserMulti">id</Value>
                </Eq>
            </And>
        </And>
    </Where>
    <OrderBy>
        <FieldRef Name="Title" Ascending="False" />
    </OrderBy>
</Query>

Otros consejos

You have multiple conditions in the And element. The And elements supports only two conditions as documented here. Rewrite the query using multiple nested And elements containing only two conditions or other And elements.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top