当周分月份时,CAML查询不起作用,即第31至第4次仅返回第31次

时间:2017-07-25 19:19:17

标签: javascript sharepoint-online caml

所以,我一直在我的SharePoint应用程序中使用此查询for Months,它一直工作得非常好。但我刚才意识到,如果我试图获得的那一周有一个像7月31日到8月4日这样的分月,它将只返回7月31日的列表项目???我已经尝试了所有我能想到的东西,让它工作,什么都没有。我如何让它工作?我不知所措。尝试使用daterange重叠标记,它只是未通过查询,尝试了我能想到的每个其他日期格式,只返回一个空的枚举器。通过MSDN查看了几个小时,在这个问题没有帮助,搜索谷歌和堆栈溢出几个小时,无法找到这个问题的答案。除了

之外,它在我的所有查询中都运行良好



 startDate = startDate.toISOString();
    endDate = endDate.toISOString();
    
    var camlQuery = new SP.CamlQuery();
    var filterString = '<View><Query>';
    filterString = filterString + '<Where>';
    filterString = filterString + '<And>';
    filterString = filterString + '<Geq>';
    filterString = filterString + '<FieldRef Name=\'EstimatedDelivery\'/>';
    filterString = filterString + '<Value IncludeTimeValue=\'TRUE\' Type = \'DateTime\'>' + startDate + '</Value>';
    filterString = filterString + '</Geq>';
    filterString = filterString + '<Leq>';
    filterString = filterString + '<FieldRef Name=\'EstimatedDelivery\'/>';
    filterString = filterString + '<Value IncludeTimeValue=\'TRUE\' Type = \'DateTime\'>' + endDate + '</Value>';
    filterString = filterString + '</Leq>';
    filterString = filterString + '</And>';
    filterString = filterString +'</Where>';
    filterString = filterString + '</Query></View>';
&#13;
 <View>
      <Query>
        <Where>
          <And>
            <Geq>
              <FieldRef Name='EstimatedDelivery'/>
              <Value IncludeTimeValue='TRUE' Type='DateTime'>startDate</Value>
            </Geq>
            <Leq>
              <FieldRef Name='EstimatedDelivery'/>
              <Value IncludeTimeValue='TRUE' Type='DateTime'>endDate</Value>
            </Leq>
          </And>
        </Where>
      </Query>
    </View>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

似乎没有人能够弄清楚为什么CAML会在分为两个月的几周内失败,所以更改了CAML查询剩余电话,现在一切正常,大约快了12倍!

var url = "/_api/web/lists/getbytitle('ListName')/Items?" +
        "$orderby=EstimatedDelivery&$filter=EstimatedDelivery ge datetime'"
+ startDate + "' and EstimatedDelivery le datetime'" + endDate + "'";

getItems(url, retrieveCalendarListItemsSucceeded);

function getItems(url,  callback) {
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            callback(data.d.results);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}