0

Microsoft Project Server Web 应用程序中,我正在尝试使用JSOM获取项目列表。

我正在关注这些示例中的代码:

这就是我要测试的内容:

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 OnlineProject Server 2013Project Server 2016

我缺少 SharePoint 或 PWA 中的任何设置吗?有同样问题的人吗?

4

1 回答 1

0

我的问题是我从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>

添加权限后,我得到项目列表。

于 2020-05-05T10:52:28.687 回答