没有获得任何 JSOM 项目 PS.ProjectContext get_projects
Not getting any project with JSOM PS.ProjectContext get_projects
在 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 中的任何设置?
有人遇到同样的问题吗?
我的问题是我 运行 此代码来自 SharePoint 应用程序 并且 应用程序清单 不包括项目权限(http://sharepoint/projectserver/projects -> 读取):
<?xml version="1.0" encoding="utf-8"?>
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest" ...>
<Properties>...</Properties>
<AppPrincipal>...</AppPrincipal>
<RemoteEndpoints>...</RemoteEndpoints>
<AppPermissionRequests>
...
<AppPermissionRequest Scope="http://sharepoint/projectserver/projects" Right="Read" />
</AppPermissionRequests>
</App>
添加权限后,我得到了项目列表。
在 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 中的任何设置? 有人遇到同样的问题吗?
我的问题是我 运行 此代码来自 SharePoint 应用程序 并且 应用程序清单 不包括项目权限(http://sharepoint/projectserver/projects -> 读取):
<?xml version="1.0" encoding="utf-8"?>
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest" ...>
<Properties>...</Properties>
<AppPrincipal>...</AppPrincipal>
<RemoteEndpoints>...</RemoteEndpoints>
<AppPermissionRequests>
...
<AppPermissionRequest Scope="http://sharepoint/projectserver/projects" Right="Read" />
</AppPermissionRequests>
</App>
添加权限后,我得到了项目列表。