2017-07-25 55 views
1

所以,我一直在我的SharePoint應用中使用這個查詢幾個月,並且它一直工作得很好。但我只是意識到,如果我試圖得到的一個月的分月份像7月31日到8月4日,它將只會返回7月31日的清單項目?我已經嘗試了所有我能想到的方法來實現這個目標,並且一無所獲。我如何使它起作用?我很茫然。嘗試使用daterange重疊標記,它只是失敗了查詢,嘗試了我能想到的每個其他格式的日期,只是返回一個空的枚舉器。通過MSDN看了好幾個小時,在這個問題上沒有任何幫助,搜索谷歌和堆棧溢出了幾個小時,並找不到這個問題的答案。它工作得很好,在我所有的querys除了CAML查詢不能正常工作,當星期已經分了個月,即只有第三十一第四隻返回31st

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>';
<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>

回答

2

似乎沒有人能弄清楚爲什麼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)); 
     } 
    }); 
} 
相關問題