您好我尝试使用javascript从sharepoint 2013查询任务。
这是我到目前为止所得到的:
var context = new SP.ClientContext.get_current();
var userSessionManager = new SP.WorkManagement.OM.UserOrderedSessionManager(context);
var userSession = userSessionManager.createSession();
var userSettingsManager = new SP.WorkManagement.OM.UserSettingsManager(context);
var locations = userSettingsManager.getAllLocations();
var locationFilter = userSettingsManager.locationFilter
var query = new SP.WorkManagement.OM.TaskQuery(context);
var myTasks = userSession.readTasks(query);
var task;
var tasks = [];
var overDue = [];
var dueSoon = [];
var anTimeDue = [];
var dateForEvaluation = new Date();
getMyTasks();
function getMyTasks() {
context.load(locations);
context.load(myTasks);
context.executeQueryAsync(onGetMyTasksSuccess, onGetMyTasksFail);
}
function onGetMyTasksSuccess() {
console.log("Successfully retrieved tasks...");
var taskEnumerator = myTasks.getEnumerator();
while (taskEnumerator.moveNext()) {
task = taskEnumerator.current;
//console.log("Task: " + task.get_id() + " - Taskname: " + task.get_name() + " - Beschreibung: " + task.get_description() + " - dueDatum: " + task.get_dueDate() + " - Startdatum: " + task.get_startDate() + " - Persönlich: " + task.get_isPersonal() + " - Fertiggestellt: " + task.get_isCompleted());
tasks.push({
taskName: task.get_name(),
description: task.get_description(),
dueDate: task.get_dueDate(),
startDate: task.get_startDate(),
personally: task.get_isPersonal(),
complete: task.get_isCompleted(),
location: task.get_locationId()
});
}
console.log(tasks);
console.log(locations)
}
// This function is executed if the above call fails
function onGetMyTasksFail(sender, args) {
console.log('Failed to get tasks. Error:' + args.get_message());
}
这段代码有效,但总能给我所有的任务。我只需要未完成的任务。好吧,我试过看看referenc页面,但没有代码示例或任何东西。
所以我的问题是如何过滤任务以仅获得未完成的任务?
任何建议或举行都会很棒,谢谢你的时间。
答案 0 :(得分:0)
我发现对我来说唯一可行的选择是给我们一个if语句,我查询is_completet方法的结果。
以下是现在的工作代码:
function onGetMyTasksSuccess() {
console.log("Successfully retrieved tasks...");
var taskEnumerator = myTasks.getEnumerator();
while (taskEnumerator.moveNext()) {
task = taskEnumerator.current;
if (task.get_isCompleted() === false) {
tasks.push({
taskName: task.get_name(),
description: task.get_description(),
dueDate: task.get_dueDate(),
startDate: task.get_startDate(),
personally: task.get_isPersonal(),
complete: task.get_isCompleted(),
location: task.get_locationId()
});
}
}
console.log(tasks);
countForForm(tasks);
}
这里的importend事情是if (task.get_isCompleted() === false)
它绝不是完美的但是我的工作还不错。遗憾的是,对于sharepoint sp.workmanagment.js,JavaScript API并没有很好的记录。