简体   繁体   中英

Is there a REST endpoint to get a list of a project's task assignments in Project Server?

I've tried sending a request to "/_api/ProjectServer/Projects('projectid')/Assignments", but all it does is return duplicates of the last assignment which is weird because the number of objects it returns is always equal to the number of assignments there are in the project.

Basically if I assign a resource to each of a hundred different tasks, the call returns 100 duplicates of the last task's assignment in the list.

I suspect it might be a bug, I'd appreciate it if someone could confirm or deny my assumption and/or let me know if there's any other way to retrieve the list of assignments in a project.

I didn't exactly know how to work with rest but I would like to provide you with litle lines of code using CSOM that, if I understood properly the question, it might help you:

private static void ListPublishedProjects()
        {
            // Get the list of projects on the server.
            projContext.Load(projContext.Projects);
            projContext.ExecuteQuery();

            var proj = projContext.Projects.First(p => p.Name == "<project name>");
            projContext.ExecuteQuery();

            //You must ckeck out the project and load it's tasks
            var draftProj = proj.CheckOut();

            projContext.Load(draftProj.Tasks);
            projContext.ExecuteQuery();  

            //Loop between all tasks
            foreach (DraftTask task in draftProj.Tasks)
            {
                // Load all assignments in that task
                projContext.Load(task.Assignments);
                projContext.ExecuteQuery();

                //Loop between al assignments
                foreach (var assignment in task.Assignments)
                {
                    projContext.Load(assignment.Owner, temp => temp.LoginName, temp => temp.Email);
                    projContext.Load(assignment.Resource);
                    projContext.ExecuteQuery();

                    Console.WriteLine("\n\t RESOURCE NAME:" + assignment.Resource.Name + " => " + assignment.ActualWork);
                }    
            }

            //Remember to publish and checkin the project when you finish your TODOs
            draftProj.Publish(true);
            draftProj.CheckIn(true);
            QueueJob qJob = projContext.Projects.Update();
            JobState jobState = projContext.WaitForQueue(qJob, 200);
        }
 }

Hope it helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM