在Microsoft Project Server Web 应用程序中,我正在尝试使用JSOM获取项目列表。
我正在关注这些示例中的代码:
- https://docs.microsoft.com/en-us/office/client-developer/project/create-retrieve-update-delete-projects-using-project-server-javascript
- https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
- https://sharepoint.stackexchange.com/questions/133935/get-project-custom-fields-project-server
- https://sharepoint.stackexchange.com/questions/76484/project-online-2013-jsom-napa-cannot-find-resource-for-the-request-processquer?rq=1
这就是我要测试的内容:
var projectContext = PS.ProjectContext.get_current();
var projects = projectContext.get_projects();
projectContext.load(projects, "Include(Name)");
projectContext.executeQueryAsync(IterateThroughProjects, handleError);
function IterateThroughProjects(response) {
var enumerator = projects.getEnumerator();
var i = 0;
while (enumerator.moveNext()) {
i++;
var project = enumerator.get_current();
console.log("Name: " + project.get_name());
}
console.log("Done. " + i + " projects found.");
}
function handleError(sender, args) {
console.log("Request failed: " + args.get_message());
}
该脚本运行没有任何错误,但结果始终是完成。找到 0 个项目。即使 PWA 中有已发布的项目。
这是我从服务器得到的响应:
[
{"SchemaVersion":"15.0.0.0","LibraryVersion":"16.0.4756.1000","ErrorInfo":null,"TraceCorrelationId":"fcde4d9f-9755-2050-31d1-da0833d8ce31"},
362,
{"_ObjectType_":"PS.ProjectCollection", "_Child_Items_":[]}
]
我尝试过Project Online、Project Server 2013和Project Server 2016。
我缺少 SharePoint 或 PWA 中的任何设置吗?有同样问题的人吗?