1

I need to put this code:

 <View>";
                  <Query>";
                  <Where>";
                   <Eq>";
                  <FieldRef Name='PublicY' />";
                 <Value Type='Choice'>Yes</Value>";
                 </Eq>";
                 </Where>";
                 </Query>";
  </View>";

(I need to retrieve all items if the item has the collumn Public News = Yes..)

In this Query:

 for (var i = 0; i < NewsLists.length; i++) {
        var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>";
        soapEnv += "    <soapenv:Body>";
        soapEnv += "        <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
        soapEnv += "            <listName>" + NewsLists[i].ListGUID + "</listName>";
        soapEnv += "            <query>";
        soapEnv += "                <Query>";
        soapEnv += "                    <OrderBy Override='TRUE'>";
        soapEnv += "                        <FieldRef Name='Created' Ascending='FALSE' />";
        soapEnv += "                    </OrderBy>";
        var currentDate = new Date();
        currentDate = currentDate.toISOString();
        soapEnv += "                    <Where>";
        soapEnv += "                        <And>";
        soapEnv += "                            <Or>";
        soapEnv += "                                <IsNull>";
        soapEnv += "                                    <FieldRef Name='DateTo' />";
        soapEnv += "                                </IsNull>";
        soapEnv += "                                <Leq>";
        soapEnv += "                                    <FieldRef Name='DateFrom' />";
        soapEnv += "                                    <Value Type='DateTime' IncludeTimeValue='True'>" + currentDate + "</Value>";
        soapEnv += "                                </Leq>";
        soapEnv += "                            </Or>";
        soapEnv += "                            <Or>";
        soapEnv += "                                <IsNull>";
        soapEnv += "                                    <FieldRef Name='DateFrom' />";
        soapEnv += "                                </IsNull>";
        soapEnv += "                                <Geq>";
        soapEnv += "                                    <FieldRef Name='DateTime' />";
        soapEnv += "                                    <Value Type='DateTime' IncludeTimeValue='True'>" + currentDate + "</Value>";
        soapEnv += "                                </Geq>";
        soapEnv += "                            </Or>";
        soapEnv += "                        </And>";
        soapEnv += "                    </Where>";
        soapEnv += "                </Query>";
        soapEnv += "            </query>";
        soapEnv += "            <queryOptions>";
        soapEnv += "                <QueryOptions>";
        soapEnv += "                    <IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>";
        soapEnv += "                </QueryOptions>";
        soapEnv += "            </queryOptions>";
        soapEnv += "            <viewFields>";
        soapEnv += "                <ViewFields>";
        soapEnv += "                    <FieldRef Name='ows_Title'/>";
        soapEnv += "                    <FieldRef Name='Ingress'/>";
        soapEnv += "                    <FieldRef Name='Visning'/>";
        soapEnv += "                    <FieldRef Name='Bild'/>";
        soapEnv += "                    <FieldRef Name='ows_FileLeafRef'/>";
        soapEnv += "                </ViewFields>";
        soapEnv += "            </viewFields>";
        var rowLimit = MaxAllNews;
        soapEnv += "            <rowLimit>" + rowLimit + "</rowLimit>";
        soapEnv += "        </GetListItems>";
        soapEnv += "    </soapenv:Body>";
        soapEnv += "</soapenv:Envelope>";
0

You need to add an extra <And>/<Or> clause in the <Where>.
All lines with 'New' in front of them are the ones you need to add.

     for (var i = 0; i < NewsLists.length; i++) {
            var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>";
            soapEnv += "    <soapenv:Body>";
            soapEnv += "        <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
            soapEnv += "            <listName>" + NewsLists[i].ListGUID + "</listName>";
            soapEnv += "            <query>";
            soapEnv += "                <Query>";
            soapEnv += "                    <OrderBy Override='TRUE'>";
            soapEnv += "                        <FieldRef Name='Created' Ascending='FALSE' />";
            soapEnv += "                    </OrderBy>";
            var currentDate = new Date();
            currentDate = currentDate.toISOString();
            soapEnv += "                    <Where>";
New         soapEnv += "                        <And>";
            soapEnv += "                            <And>";
            soapEnv += "                                <Or>";
            soapEnv += "                                    <IsNull>";
            soapEnv += "                                        <FieldRef Name='DateTo' />";
            soapEnv += "                                    </IsNull>";
            soapEnv += "                                    <Leq>";
            soapEnv += "                                        <FieldRef Name='DateFrom' />";
            soapEnv += "                                        <Value Type='DateTime' IncludeTimeValue='True'>" + currentDate + "</Value>";
            soapEnv += "                                    </Leq>";
            soapEnv += "                                </Or>";
            soapEnv += "                                <Or>";
            soapEnv += "                                    <IsNull>";
            soapEnv += "                                        <FieldRef Name='DateFrom' />";
            soapEnv += "                                    </IsNull>";
            soapEnv += "                                    <Geq>";
            soapEnv += "                                        <FieldRef Name='DateTime' />";
            soapEnv += "                                        <Value Type='DateTime' IncludeTimeValue='True'>" + currentDate + "</Value>";
            soapEnv += "                                    </Geq>";
            soapEnv += "                                </Or>";
            soapEnv += "                            </And>";
New         soapEnv += "                            <Eq>";
New         soapEnv += "                                <FieldRef Name='PublicY' />";
New         soapEnv += "                                <Value Type='Choice'>Yes</Value>";
New         soapEnv += "                            </Eq>";
New         soapEnv += "                        </And>";
            soapEnv += "                    </Where>";
            soapEnv += "                </Query>";
            soapEnv += "            </query>";
            soapEnv += "            <queryOptions>";
            soapEnv += "                <QueryOptions>";
            soapEnv += "                    <IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>";
            soapEnv += "                </QueryOptions>";
            soapEnv += "            </queryOptions>";
            soapEnv += "            <viewFields>";
            soapEnv += "                <ViewFields>";
            soapEnv += "                    <FieldRef Name='ows_Title'/>";
            soapEnv += "                    <FieldRef Name='Ingress'/>";
            soapEnv += "                    <FieldRef Name='Visning'/>";
            soapEnv += "                    <FieldRef Name='Bild'/>";
            soapEnv += "                    <FieldRef Name='ows_FileLeafRef'/>";
            soapEnv += "                </ViewFields>";
            soapEnv += "            </viewFields>";
            var rowLimit = MaxAllNews;
            soapEnv += "            <rowLimit>" + rowLimit + "</rowLimit>";
            soapEnv += "        </GetListItems>";
            soapEnv += "    </soapenv:Body>";
            soapEnv += "</soapenv:Envelope>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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