CAML 查询在周已拆分月份时不起作用,即仅第 31-4 日 return 31 日
CAML query not working when week has split month i.e 31st-4th only return 31st
因此,几个月来我一直在我的 SharePoint 应用程序中使用此查询,它一直运行良好。但我刚刚意识到,如果我想要获得的那一周有一个像 7 月 31 日到 8 月 4 日这样的拆分月份,它只会 return 列出 7 月 31 日的项目???我已经尝试了所有我能想到的方法来使它正常工作,但一无所获。我如何让它工作?我不知所措。尝试使用 daterange 重叠标记,它只是查询失败,尝试了我能想到的所有其他格式的日期,只是 returns 是一个空的枚举器。通过 MSDN 查找了几个小时,在这个问题上没有帮助,搜索了 google 和堆栈溢出几个小时,找不到这个问题的答案。除了
之外,它在我的所有查询中都运行良好
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>
似乎没有人能弄清楚为什么 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));
}
});
}
因此,几个月来我一直在我的 SharePoint 应用程序中使用此查询,它一直运行良好。但我刚刚意识到,如果我想要获得的那一周有一个像 7 月 31 日到 8 月 4 日这样的拆分月份,它只会 return 列出 7 月 31 日的项目???我已经尝试了所有我能想到的方法来使它正常工作,但一无所获。我如何让它工作?我不知所措。尝试使用 daterange 重叠标记,它只是查询失败,尝试了我能想到的所有其他格式的日期,只是 returns 是一个空的枚举器。通过 MSDN 查找了几个小时,在这个问题上没有帮助,搜索了 google 和堆栈溢出几个小时,找不到这个问题的答案。除了
之外,它在我的所有查询中都运行良好 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>
似乎没有人能弄清楚为什么 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));
}
});
}