我正在过滤SharePoint Online上的查找列,但是如果在浏览器上进行检查并且过滤无法正常进行,则会不断出现错误。
我已经使用jquery.SPServices.SPGetCurrentUser来获取登录用户的详细信息。然后使用CAML查询进行过滤并获取列表活动计划。
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script
src="//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript">
let custom = {}
custom.myQuery = jQuery;
console.log(custom)
console.log($().SPServices.SPGetCurrentUser({
fieldNames: ["ID", "Name", "Title", "Email","DepartMent", "JobTitle",
"FirstName", "LastName", "UserName", "SIP Address"],
debug: false
}));
var userId = $().SPServices.SPGetCurrentUser({
fieldName: "ID",
debug: false
})
_spBodyOnLoadFunctionNames.push("loadSP")
function loadSP() {
var query = `<Query><Where><And><Eq><FieldRef Name='AssignedTo'
LookupId='TRUE'/><Value Type='Integer'>${userId}</Value></Eq><Eq>
<FieldRef Name='Status' LookupId='TRUE'/><Value
Type='Text'>Approved</Value></Eq></And></Where></Query>`;
custom.myQuery().SPServices({
operation: "GetListItems",
async: false,
listName: "Activity Plan",
CAMLQuery: query,
//CAMLQueryOptions: "<QueryOptions><ViewAttributes
Scope='RecursiveAll' IncludeRootFolder='True' /></QueryOptions>",
CAMLViewFields: `<ViewFields>
<FieldRef Name='Deliverable' />
<FieldRef Name='Task Status' />
<FieldRef Name='ID' />
</ViewFields>`,
completefunc: function (xData, Status) {
var newSites = "(none)";
var ID = "0";
console.log(xData)
$(xData.responseXML).find("z\\:row, row").each(function () {
var DeliverableLookup = $(this).attr("Deliverable");
var owId = $(this).attr("ID");
if (DeliverableLookup != '') {
var newValue = DeliverableLookup;
if (newSites.indexOf(newValue) == -1) {
newSites = newSites + "|" + newValue;
ID += '| ' + owId;
}
}
});
updateValues(newSites, ID);
}
});
}
function getField(fieldType,fieldTitle) {
var docTags = document.getElementsByTagName(fieldType);
for (var i=0; i < docTags.length; i++) {
if (docTags[i].title == fieldTitle) {
return docTags[i];
}
}
return false;
}
function updateValues(newSites, ID) {
lookupFieldText = getField('select','My Planned Tasks');
//lookupFieldId = document.getElementById(lookupFieldText.id);
$(lookupFieldText).empty();
let arrSites = newSites.split('|');
let arrId = ID.split('|');
for (let i = 0; i < arrSites.length; i++){
$(lookupFieldText).append(`<option id='${arrId[i]}'
value='${arrSites[i]}'> ${arrSites[i]} </option>`)
}
//lookupFieldText.choices = newSites;
}
function CustomAction(){
console.log("done loading")
}
</script>
我希望查询列“我的计划的任务”仅显示我创建的状态为“已批准”的可交付成果,但是它将返回所有任务。
答案 0 :(得分:0)
检查控制台记录的数据并查看返回的内容,如果没有返回任何内容,请检查您的状态是否为true,如果不是,则查询错误。。检查查询中的空格。