0
votes

I suppose I have found another SP bug... but maybe I do something wrong. I have this POST request:

https://dmsdev/coll/f7c592adcb4c4e5996c2de00d444a94c/_api/Web/Lists/GetByTitle('1')/GetItems?$expand=ContentType&$select=Id,SonarDocId,ContentTypeId,EncodedAbsURL,Modified,ContentType/Name

With body:

{"query":{"ViewXml":"<View><Query><OrderBy><FieldRef Name='Modified'/></OrderBy></Query><RowLimit>50</RowLimit></View>","ListItemCollectionPosition":{"PagingInfo":"Paged=TRUE&p_Modified=2017-08-10T07:25:28"}}}

As you can see I do a CAML query with ORDER BY Modified column and I want to take items starting from the item after the item with some modified date but looks like this is not working... I mean similar request on other SP environment works, and on the other env it is not working... it takes all items starting from the first one after ordering by modified... I have no idea what is wrong :/

2

2 Answers

0
votes

You could check my sample test script.

<script type="text/javascript">              
    function restCallwithCaml(listName, caml,PID) {
        /// get the site url
        var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
        /// set request data
        var data = {
            "query": {
                "__metadata":
                { "type": "SP.CamlQuery" },
                "ViewXml": caml,
                "ListItemCollectionPosition": {
                    "PagingInfo": "Paged=TRUE&p_ID=" + PID
                }
            }
        };
        /// make an ajax call
        return $.ajax({
            url: siteUrl + "/_api/web/lists/GetByTitle('" + listName + "')/GetItems",
            method: "POST",
            data: JSON.stringify(data),
            headers: {
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                'content-type': 'application/json;odata=verbose',
                'accept': 'application/json;odata=verbose'
            }
        });
    }
    function GetItemsPaging() {
        var pageLimit = 2;
        var pageNumber = 0;
        var caml = "<View><Query><Where><Geq><FieldRef Name='ID'/><Value Type='Number'>1</Value></Geq></Where></Query><RowLimit>" + pageLimit + "</RowLimit></View>";
        var listName = "ChildB";
        restCallwithCaml(listName, caml, pageNumber).done(function (data) {
            if (data.d.results.length == pageLimit) {
                pageNumber++;
                //add to array or display
                var PID=data.d.results[data.d.results.length - 1].Id;
                alert(PID);
                restCallwithCaml(listName, caml, PID).done(function (data) {
                    //add to array or display
                    alert(data.d.results[data.d.results.length - 1].Id);
                })
            }
        });
    }
</script>

Original thread

0
votes

The problem was with my understanding of how this whole thing works + time zones I had to write a paging query eg:

Paged=TRUE&p_ID=10&p_Modified=2018-12-14T18:52:00

So I had to add p_Modified parameter from the last item from the previous page... Additionally this data has to be in UTC, so for example I can execute get query with the time returned by the CAML

https://server/site/_api/web/RegionalSettings/TimeZone/localTimeToUTC(@date)?@date='2018-12-14T11:52:00'

And date returned by this call should be passed in p_Modified.