In a Microsoft Project Server web app I am trying to get the list of projects using JSOM.
I am following the code in these examples:
- https://learn.microsoft.com/en-us/office/client-developer/project/create-retrieve-update-delete-projects-using-project-server-javascript
- https://learn.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
This is what I am running to test:
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());
}
The script runs without any error but the result is always Done. 0 projects found. even though there are published projects in the PWA.
This is the response I get from the server:
[
{"SchemaVersion":"15.0.0.0","LibraryVersion":"16.0.4756.1000","ErrorInfo":null,"TraceCorrelationId":"fcde4d9f-9755-2050-31d1-da0833d8ce31"},
362,
{"_ObjectType_":"PS.ProjectCollection", "_Child_Items_":[]}
]
I have tried against Project Online, Project Server 2013 and Project Server 2016.
Is there any setting in SharePoint or PWA I am missing? Anyone with the same problem?