在CAML查询中插入WHERE子句-使用SharePoint、SPServices、JavaScript和jQuery
我正试图在CAML查询中插入WHERE子句,以过滤日期列中的NULL(我希望返回在Assign date列中没有日期的所有行) 这是一个SharePoint列表。代码使用SPServices、jQuery和JavaScript 我花了相当长的时间来实现这一点——我在做这种集成方面的经验很少,在使用CAML方面的经验更少 这是代码的CAML查询段:在CAML查询中插入WHERE子句-使用SharePoint、SPServices、JavaScript和jQuery,javascript,jquery,sharepoint,caml,spservices,Javascript,Jquery,Sharepoint,Caml,Spservices,我正试图在CAML查询中插入WHERE子句,以过滤日期列中的NULL(我希望返回在Assign date列中没有日期的所有行) 这是一个SharePoint列表。代码使用SPServices、jQuery和JavaScript 我花了相当长的时间来实现这一点——我在做这种集成方面的经验很少,在使用CAML方面的经验更少 这是代码的CAML查询段: function loadPrioritizedList() { $("#tasksUL").empty(); $().SPServi
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><Eq><FieldRef Name=Assign_x0020_Date' /><Value Type='Date and Time'>IsNull</Value></Eq></Where>" +
函数加载优先级列表(){
$(“#tasksUL”).empty();
$().SPServices({
操作:“GetListItems”,
webURL:myURL,
listName:targetListName,
CAMLViewFields:“”,
CAMLQuery:“”+
'' +
'' +
'' +
'',
CAMLRowLimit:listrowlimit,
completefunc:函数(扩展数据、状态){
$(扩展数据.responseXML).SPFilterNode(“z:row”).each(函数(){
var tdHtml=“”;
tdHtml=tdHtml+“”+PriorityFormat($(this).attr(“ows_Priority_x0020_Number”);+“”;
tdHtml=tdHtml+“”;
tdHtml=tdHtml++$(this).attr(“ows_优先级”)++;
tdHtml=tdHtml+“”+TopItem($(this).attr(“ows_Top_x0020_Item_x003f”)+“”;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_Purpose”)+“”;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_Item_x002d_Task_x0020_Order”)+“”;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_模式”)+“”;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_Task_x0020_Type”)+“”;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_Work_x0020_Status”)+“”;
tdHtml=tdHtml+“”+FormatDate($(this).attr(“ows_DueDate”)+“”;
tdHtml=tdHtml+“”+FormatDate($(this).attr(“ows_DAK_x0020_Date”)+“”;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_DAK_x0020_No”)+“”;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_AssignedTo”)+“”;
tdHtml=tdHtml++$(this.attr(“ows_Money_x0020_Estimate”)+;
tdHtml=tdHtml+“”+StringChk($(this).attr(“ows_ItemStatus”)+“”;
tdHtml=tdHtml+“”+FormatDate($(this).attr(“ows_Assign_x0020_Date”)+“”;
tdHtml=tdHtml+“”;
$(“#tasksUL”).append(tdHtml);
});
}
});
我们将非常感谢您的帮助,并提前向您表示感谢
更新:
代码的最新版本如下。我添加了“WHERE”条款:
"<Where><Eq><FieldRef Name=Assign_x0020_Date' /><Value Type='Date and Time'>IsNull</Value></Eq></Where>" +
“由于我使用我的框架,我并不真正关心CAML,但它应该是这样的:
<query>
<Query>
<Where>
<IsNull><FieldRef Name="Assign_x0020_Date"></FieldRef></IsNull>
</Where>
</Query>
</query>
顺便说一句,您可能想尝试我的框架:
语法将是(对于相同的事情):
函数加载优先级列表(){
$(“#tasksUL”).empty();
$SP().list(targetListName).get({
字段:“优先级\u x0020\u编号、编辑\u x0020\u链接、优先级、最上面的\u x0020\u项目\u x003f\u、目的、项目\u x002d\u任务\u x0020\u顺序、模式、工作\u x0020\u状态、截止日期、任务\u x0020\u类型、DAK\u x0020\u日期、DAK\u x0020\u编号、分配到、资金\u x0020\u估算、项目状态、分配\u x0020\u日期”,
其中:“分配日期=”,
订购人:“优先权号描述”,
rowlimit:listrowlimit
},函数(扩展数据){
var tdHTML=“”;
for(var i=xData.length;i--;){
tdHtml+=“”;
tdHtml+=“”+PriorityFormat(扩展数据[i].getAttribute(“优先级”\ux0020\uNumber”);+“”;
tdHtml+='';
tdHtml++=“扩展数据[i].getAttribute(“优先级”)++;
tdHtml+=“”+TopItem(扩展数据[i].getAttribute(“Top\u x0020\u Item\u x003f”)+“”;
tdHtml++=“StringChk(扩展数据[i].getAttribute(“目的”)+”;
tdHtml++=“StringChk(扩展数据[i].getAttribute(“项目\u x002d\u任务\u x0020\u顺序”))+”;
tdHtml+=“”+StringChk(扩展数据[i].getAttribute(“模式”)+“”;
tdHtml+=“”+StringChk(扩展数据[i].getAttribute(“任务类型”)+“”;
tdHtml+=“”+StringChk(扩展数据[i].getAttribute(“工作状态”)+“”;
tdHtml+=“”+FormatDate(扩展数据[i].getAttribute(“DueDate”)+“”;
tdHtml+=“”+FormatDate(扩展数据[i].getAttribute(“DAK_x0020_Date”)+“”;
tdHtml+=“”+StringChk(扩展数据[i].getAttribute(“DAK_x0020_No”)+“”;
tdHtml++=“StringChk(扩展数据[i].getAttribute(“AssignedTo”)+”;
tdHtml+=“”+xData[i].getAttribute(“货币”估计数);
tdHtml+=“”+StringChk(扩展数据[i].getAttribute(“ItemStatus”)+“”;
tdHtml+=“”+FormatDate(扩展数据[i].getAttribute(“分配日期”)+“”;
tdHtml+=“”;
}
$(“#tasksUL”).append(tdHtml);
}
});
啊,答案是必须使用IsNull。我修改了代码:
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><Eq><FieldRef Name=Assign_x0020_Date' /><Value Type='Date and Time'>IsNull</Value></Eq></Where>" +
“”+
感谢这篇文章:
再次感谢您的帮助!不幸的是,我无法使用上述框架,无法实现您的框架。看看您的解决方案,我希望我可以!这是我回答的第一部分:-)@AymKdn-哦,哇,您说得对!我很抱歉-我这些天睡眠不多,一定是失去了知觉!
"<Where><IsNull><FieldRef Name=Assign_x0020_Date' /></IsNull></Where>" +