我正在尝试将 WHERE 子句插入到我的 CAML 查询中,以过滤日期列是否为 NULL(我想返回在“分配日期”列中没有日期的所有行)。
这是一个 SharePoint 列表。该代码使用 SPServices、jQuery 和 JavaScript
我有很长的时间来解决这个问题 - 我在进行这种类型的集成方面经验很少,而且在使用 CAML 方面的经验也更少。
这是代码的 CAML 查询段:
function loadPrioritizedList() {
$("#tasksUL").empty();
$().SPServices({
operation: "GetListItems",
webURL: myURL,
listName: targetListName,
CAMLViewFields: "<ViewFields><FieldRef Name='Priority_x0020_Number' /><FieldRef Name='Edit_x0020_Link' /><FieldRef Name='Priority' /><FieldRef Name='Top_x0020_Item_x003f_' /><FieldRef Name='Purpose' /><FieldRef Name='Item_x002d_Task_x0020_Order' /><FieldRef Name='Mode' /><FieldRef Name='Work_x0020_Status' /><FieldRef Name='DueDate' /><FieldRef Name='Task_x0020_Type' /><FieldRef Name='DAK_x0020_Date' /><FieldRef Name='DAK_x0020_No' /><FieldRef Name='AssignedTo' /><FieldRef Name='Money_x0020_Estimate' /><FieldRef Name='ItemStatus' /><FieldRef Name='Assign_x0020_Date' /></ViewFields>",
CAMLQuery: '<Query>' +
'<OrderBy>' +
'<FieldRef Name="Priority_x0020_Number" />' +
'</OrderBy>' +
'</Query>',
CAMLRowLimit: listrowlimit,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var tdHtml = "<tr class='sortable_row' id=" + $(this).attr("ows_ID") + ">";
tdHtml = tdHtml + "<td style=\"width:60px;\">" + PriorityFormat($(this).attr("ows_Priority_x0020_Number")); + "</td>";
tdHtml = tdHtml + '<td style=\"width:49px;\"><a href=\"'+($(this).attr("ows_Edit_x0020_Link")).split(", ")[1] + '\">' + ($(this).attr("ows_Edit_x0020_Link")).split(", ")[1] + '</a></td>';
tdHtml = tdHtml + "<td style=\"width:83px;\">" + $(this).attr("ows_Priority") + "</td>";
tdHtml = tdHtml + "<td style=\"width:63px;\">" + TopItem($(this).attr("ows_Top_x0020_Item_x003f_")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:300px;\">" + StringChk($(this).attr("ows_Purpose")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:125px;\">" + StringChk($(this).attr("ows_Item_x002d_Task_x0020_Order")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:40px;\">" + StringChk($(this).attr("ows_Mode")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:75px;\">" + StringChk($(this).attr("ows_Task_x0020_Type")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:150px;\">" + StringChk($(this).attr("ows_Work_x0020_Status")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:100px;\">" + FormatDate($(this).attr("ows_DueDate")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:100px;\">" + FormatDate($(this).attr("ows_DAK_x0020_Date")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:100px;\">" + StringChk($(this).attr("ows_DAK_x0020_No")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:300px;\">" + StringChk($(this).attr("ows_AssignedTo")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:125px;\">" + $(this).attr("ows_Money_x0020_Estimate") + "</td>";
tdHtml = tdHtml + "<td style=\"width:75px;\">" + StringChk($(this).attr("ows_ItemStatus")) + "</td>";
tdHtml = tdHtml + "<td style=\"width:100px;\">" + FormatDate($(this).attr("ows_Assign_x0020_Date")) + "</td>";
tdHtml = tdHtml + "</tr>";
$("#tasksUL").append(tdHtml);
});
}
});
任何帮助将不胜感激,我提前感谢您。
更新:代码的最新版本如下。我已将“WHERE”子句添加为:
"<Where><Eq><FieldRef Name=Assign_x0020_Date' /><Value Type='Date and Time'>IsNull</Value></Eq></Where>" +
但它仍然没有返回任何结果。在这一点上,我不确定我在这里缺少什么。
上面添加的查询如下所示:
function loadPrioritizedList() {
$("#tasksUL").empty();
$().SPServices({
operation: "GetListItems",
webURL: myURL,
listName: targetListName,
CAMLViewFields: "<ViewFields><FieldRef Name='Priority_x0020_Number' /><FieldRef Name='Edit_x0020_Link' /><FieldRef Name='Priority' /><FieldRef Name='Top_x0020_Item_x003f_' /><FieldRef Name='Purpose' /><FieldRef Name='Item_x002d_Task_x0020_Order' /><FieldRef Name='Mode' /><FieldRef Name='Work_x0020_Status' /><FieldRef Name='DueDate' /><FieldRef Name='Task_x0020_Type' /><FieldRef Name='DAK_x0020_Date' /><FieldRef Name='DAK_x0020_No' /><FieldRef Name='AssignedTo' /><FieldRef Name='Money_x0020_Estimate' /><FieldRef Name='ItemStatus' /><FieldRef Name='Assign_x0020_Date' /></ViewFields>",
CAMLQuery: '<Query>' +
"<Where><Eq><FieldRef Name='Assign_x0020_Date' /><Value Type='Date and Time'>IsNull</Value></Eq></Where>" +
'<OrderBy>' +
'<FieldRef Name="Priority_x0020_Number" />' +
'</OrderBy>' +
'</Query>',