Frage

For a project I have to sync hours from an external program to EPM. There is no requirement to use the Client Side Object Model of EPM 2013 or the PSI. But because Microsoft recommends the CSOM on their website for all new applications I tried to implement it with the CSOM. The first thing I wanted to test is to get all the hours, with the following code: (It isn't the most beautiful code because it is for testing purposes)

    private static void GetTimesheets()
    {
        ProjectContext projContext = new ProjectContext("http://tfspsdemo/PWA/");       
        projContext.Load(projContext.TimeSheetPeriods);
        projContext.ExecuteQuery();

        foreach (var period in projContext.TimeSheetPeriods)
        {
                projContext.Load(period.TimeSheet);
                projContext.ExecuteQuery();
                Console.WriteLine(period.Name);
                try
                {
                        string tempName = period.TimeSheet.Name;

                        projContext.Load(period.TimeSheet.Lines);
                        projContext.ExecuteQuery();

                        Console.WriteLine(period.TimeSheet.Name);

                        foreach (var line in period.TimeSheet.Lines)
                        {
                            try
                            {
                                projContext.Load(line);
                                projContext.Load(line.Work);
                                projContext.ExecuteQuery();


                                foreach (var workLine in line.Work)
                                {
                                    Console.WriteLine(workLine.ActualWork);
                                }
                            }
                            catch (Exception) { }

                            Console.WriteLine("Total: {0}", line.TotalWork);
                        }                        
                }
                catch (ServerObjectNullReferenceException) { }                
        }
    }

But with above code I get only the code for the current user that is logged in, even if it is a person with rights to see other users hours. But what I want is to see all the hours of all the persons that have booked hours in EPM for a specific project plan. So I can later use this information to sync the hours from an external program to EPM. I thought I can solve this with impersonation but:

 ProjectContext projContext = new ProjectContext("http://tfspsdemo/PWA/"); 
 projContext.Credentials = new NetworkCredentials("username", "password");

But this isn't what I want because I have to do this for each user. And also I can't get the passwords of all users.

Does anyone now a solution to solve this problem and/or any suggestions? Solutions with the EPM PSI are also appreciated!

Thanks in advance!

War es hilfreich?

Lösung

Impersonation is not yet implemented in Project Sever 2016/Project Online. Please vote here: https://microsoftproject.uservoice.com/forums/218133-microsoft-project/suggestions/32981722-impersonation-support-for-csom-to-read-other-user

Thanks, Werner

Andere Tipps

There are two modes in Proect server 2013. Proect server and SharePoint mode. I was able to get the above working in SharePoint mode, but alas I cannot read even Timesheet Periods as it says CSOMUnkownUser in Project server mode even after passing in the credentials. What mode are you running in currently on the server

This is probably a little late, but to access that kind of data in a provider/auto hosted app you need to access the sharepoint server through OData. CSOM is only intended to provide data from the current user context.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top