none
Add hours to task in project server 2013 RRS feed

  • Question

  • Hello,

    For integration with a custom application I need to add hours for resources to project server 2013. These hours must be coupled to a (existing)  task (and resource) in project server. Also I need the possibility to delete hours for a specific person per task.

    I tried to achieve above with CSOM without succes. When getting the tasks I couldn't add hours. (First created a method that prints the information, but with this I am stuck.)

            private static void GetTasks()
            {
                var projects = projContext.Projects;
    
                projContext.Load(projects);
                projContext.ExecuteQuery();
    
                foreach (var project in projects)
                {
                    projContext.Load(project.Tasks);
                    projContext.ExecuteQuery();
    
                    Console.WriteLine(project.Name);
    
                    foreach (var task in project.Tasks)
                    {
                        projContext.Load(task.Assignments);
                        projContext.ExecuteQuery();
                        Console.WriteLine("\t" + task.Name);
    
                        foreach (var assignment in task.Assignments)
                        {
                            projContext.Load(assignment.Owner, temp => temp.LoginName, temp => temp.Email);
                            projContext.Load(assignment.Resource);
                            projContext.ExecuteQuery();
    
                            Console.WriteLine("\t\t" + assignment.Owner.Email + " " + assignment.ActualWork);
                        }
                    }
    
                    Console.WriteLine("-----");
                    Console.WriteLine();
                }
            }

    Another option I thought was getting the information from the timesheets, without succes because Timesheet remains null

            private static void GetTimesheets()
            {
                var timesheets = projContext.LoadQuery(projContext.TimeSheetPeriods.IncludeWithDefaultProperties(item => item.TimeSheet));
                projContext.ExecuteQuery();
    
                foreach (var timePeriod in timesheets)
                {    
                    //Option one, Timesheet stays null
                    projContext.Load(timePeriod.TimeSheet);
                    projContext.ExecuteQuery();
    
                    //Option two, Timesheet stays null
                    var timesheet = timePeriod.TimeSheet;
                    projContext.Load(timesheet);
                    projContext.ExecuteQuery();
                }
            }

    Does anyone now how to achieve this using CSOM or PSI? Maybe some examples/references to implement above requirements?

    Thanks in advance



    • Edited by mrtentje Monday, November 4, 2013 9:36 PM
    Monday, November 4, 2013 9:35 PM

Answers

  • Hi,

    While you can update the Assignment and Task objects directly to do what you want, that would require the project to be checked out and such so that can cause issues if the PM's are working at the same time.

    That's exactly what the statusing methods are designed to handle, specifically they allow for the submission of Status Updates (ie progress) on assigned tasks. In fact it is exactly the same way that My Tasks in PWA works for users (or if you like the Timesheets, minus the timesheet itself).

    Hence the advice to use that method to submit work.

    There was a good tool to allow you to test / experiment with Statusing and the PSI in 2007; http://msdn.microsoft.com/en-us/library/office/bb428819(v=office.12).aspx , what it demonstrates well is what can and can't be done with the Statusing engine, much of that is still valid today (I assume even with the CSOM).

    Otherwise best bet is to experiment via PWA, basically what you can do via My Tasks is most of what you can do with the API, so test, simulate and confirm that you can do exactly what you want, then via the Statusing methods you should be able to implement that in CSOM, etc.

    HTH,

    Martin


    Martin Laukkanen (Project Server Blog - www.nearbaseline.com/blog)

    • Marked as answer by mrtentje Tuesday, November 5, 2013 10:00 PM
    Tuesday, November 5, 2013 9:55 PM

All replies

  • Hi,

    So you need to update assignments on tasks with actual hours?

    What you need (PSI or CSOM) is to use the Statusing service:

    If you're using 2013 then definitely you should use the CSOM rather than PSI, however the documentation is pretty sparse at the moment so you may need to work out some of the CSOM methods for yourself.

    However the PSI link above with background information on the Statusing service of Project Server is relevant for both CSOM and PSI.

    HTH,


    Martin Laukkanen (Project Server Blog - www.nearbaseline.com/blog)

    Tuesday, November 5, 2013 4:22 AM
  • Hello,

    First of all thanks for pointing me in the right direction. Yes first I want to update assignments on tasks with actual hours. During creating above methods I also saw the Assignment object. During inspecting the properties of this object in Visual Studio I discovered that all the hours (of several days and periods) are all wrapped/counted to the Status object (so all the hours are added, couldn't find a relation when the hours exactly were booked). What happened when I add hours using updating an assignment? Do I have control for which days in the timesheet these hours for a specific task for a specific person are added?

    Thanks in advance!

    Tuesday, November 5, 2013 7:25 AM
  • Hi,

    While you can update the Assignment and Task objects directly to do what you want, that would require the project to be checked out and such so that can cause issues if the PM's are working at the same time.

    That's exactly what the statusing methods are designed to handle, specifically they allow for the submission of Status Updates (ie progress) on assigned tasks. In fact it is exactly the same way that My Tasks in PWA works for users (or if you like the Timesheets, minus the timesheet itself).

    Hence the advice to use that method to submit work.

    There was a good tool to allow you to test / experiment with Statusing and the PSI in 2007; http://msdn.microsoft.com/en-us/library/office/bb428819(v=office.12).aspx , what it demonstrates well is what can and can't be done with the Statusing engine, much of that is still valid today (I assume even with the CSOM).

    Otherwise best bet is to experiment via PWA, basically what you can do via My Tasks is most of what you can do with the API, so test, simulate and confirm that you can do exactly what you want, then via the Statusing methods you should be able to implement that in CSOM, etc.

    HTH,

    Martin


    Martin Laukkanen (Project Server Blog - www.nearbaseline.com/blog)

    • Marked as answer by mrtentje Tuesday, November 5, 2013 10:00 PM
    Tuesday, November 5, 2013 9:55 PM
  • Hi,

    I'm not sure about update, but I noticed something in matter of nulled timesheets. At first, TimePeriods. Time Periods may have (important) TimeSheets. Unfortunately, when TimeSheet does not exists, it doesn’t mean, that it is null. You can observer an exception after you tried to read an attribute. That’a a problem, and you have to use [try-catch] block. I had a situation, that it was 52 periods (one for each week), but TimeSheet was an existing object from 44<sup>th</sup>. I hope it helps you.

    Andrew

    Wednesday, November 13, 2013 9:01 PM
  • During development I experienced this issue myself. The problem I currently have is that I can't add hours to a timesheet (and because of this also not to a task). This because of the fact that I only see the hours/timesheet of the user currently logged in. I thought impersonation can solve the problem but I found that with CSOM I must enter the credentials for the specified person. With 800 users accross different project plans in EPM I don't think it will be a good idea to store and/or retrieve all the passwords and usernames.

    projContext.Credentials = ...

    Thursday, November 14, 2013 3:40 PM