none
assign resources to a task programmatically RRS feed

  • Question

  • hello forum members,

    does anyone have any code samples on how to assign a resource or a group of resources to a task programmatically?

    here is what i got so far:

                                    

                for (int i = 0; i < numProjects; i++)
                {
                    projectUids[i] = Guid.NewGuid();
                    projDs[i] = new backendProject.ProjectDataSet();
                    backendProject.ProjectDataSet.ProjectRow projRow = projDs[i].Project.NewProjectRow();

                    projRow.PROJ_TYPE = projectType;
                    projRow.PROJ_UID = projectUids[i];
                    projRow.PROJ_NAME = "WCFTEST_" + projectUids[i].ToString();

                    projDs[i].Project.AddProjectRow(projRow);

                    // Add some tasks
                    backendProject.ProjectDataSet.TaskRow taskOne = projDs[i].Task.NewTaskRow();
                    taskOne.PROJ_UID = projRow.PROJ_UID;
                    taskOne.TASK_UID = Guid.NewGuid();
                    //Task Duration format must be specified
                    taskOne.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
                    taskOne.TASK_DUR = 4800;  // 8 hours in duration units (minute/10)
                    taskOne.TASK_NAME = "Task One";
                    taskOne.TASK_START_DATE = System.DateTime.Now.AddDays(1);
                    projDs[i].Task.AddTaskRow(taskOne);

    //TODO: assign resources to this task so that they can log time to it
                }


    tatiana

    Thursday, August 21, 2014 10:40 PM

Answers

  • Hey Tatiana,

    There are a few steps to this, first, the resource needs to be added to the project:

    SvcProject.ProjectTeamDataSet ptDS;
    
    using( OperationContextScope ocs = new OperationContextScope( projectClient.InnerChannel ) ) {
                   ptDS = projectClient.ReadProjectTeam( projectUID );
                }
    
    SvcProject.ProjectTeamDataSet.ProjectTeamRow newResource = ptDS.ProjectTeam.NewProjectTeamRow();
    
                newResource.NEW_RES_UID = RES_UID;
                newResource.RES_UID = Guid.NewGuid();
                newResource.RES_NAME = GetResourceName( RES_UID );
                newResource.RES_IS_ENTERPRISE_RESOURCE = true;
                newResource.PROJ_UID = projectUID;
    
                ptDS.ProjectTeam.AddProjectTeamRow( newResource );
    
    //TODO Project check out and session logic here
    
    projectClient.QueueUpdateProjectTeam( jobGUID, sessionUid, projectUID, ptDS );
    
    

    After this, you can read in your project by calling the ReadProjectEntities method of the project service (I think 64 is the enumeration for assignments), then you would do something like this:

     SvcProject.ProjectDataSet.AssignmentRow newAssignmentRow = pjDS.Assignment.NewAssignmentRow();
    
                newAssignmentRow.ASSN_UID = Guid.NewGuid();
                newAssignmentRow.TASK_UID = TASK_UID;
                newAssignmentRow.PROJ_UID = projectUID;
                newAssignmentRow.RES_UID = RES_UID;
                newAssignmentRow.RES_UID_OWNER = RES_UID;
                newAssignmentRow.ASSN_START_DATE = ASSN_START_DATE;
                newAssignmentRow.ASSN_FINISH_DATE = ASSN_FINISH_DATE;
    
                pjDS.Assignment.AddAssignmentRow( newAssignmentRow );

    (what I have included above is the bare minimum for adding an assignment).

    Hope this helps,


    120811049008

    • Marked as answer by tatiana obrien Thursday, August 28, 2014 12:13 AM
    Monday, August 25, 2014 4:42 PM

All replies

  • Hey Tatiana,

    There are a few steps to this, first, the resource needs to be added to the project:

    SvcProject.ProjectTeamDataSet ptDS;
    
    using( OperationContextScope ocs = new OperationContextScope( projectClient.InnerChannel ) ) {
                   ptDS = projectClient.ReadProjectTeam( projectUID );
                }
    
    SvcProject.ProjectTeamDataSet.ProjectTeamRow newResource = ptDS.ProjectTeam.NewProjectTeamRow();
    
                newResource.NEW_RES_UID = RES_UID;
                newResource.RES_UID = Guid.NewGuid();
                newResource.RES_NAME = GetResourceName( RES_UID );
                newResource.RES_IS_ENTERPRISE_RESOURCE = true;
                newResource.PROJ_UID = projectUID;
    
                ptDS.ProjectTeam.AddProjectTeamRow( newResource );
    
    //TODO Project check out and session logic here
    
    projectClient.QueueUpdateProjectTeam( jobGUID, sessionUid, projectUID, ptDS );
    
    

    After this, you can read in your project by calling the ReadProjectEntities method of the project service (I think 64 is the enumeration for assignments), then you would do something like this:

     SvcProject.ProjectDataSet.AssignmentRow newAssignmentRow = pjDS.Assignment.NewAssignmentRow();
    
                newAssignmentRow.ASSN_UID = Guid.NewGuid();
                newAssignmentRow.TASK_UID = TASK_UID;
                newAssignmentRow.PROJ_UID = projectUID;
                newAssignmentRow.RES_UID = RES_UID;
                newAssignmentRow.RES_UID_OWNER = RES_UID;
                newAssignmentRow.ASSN_START_DATE = ASSN_START_DATE;
                newAssignmentRow.ASSN_FINISH_DATE = ASSN_FINISH_DATE;
    
                pjDS.Assignment.AddAssignmentRow( newAssignmentRow );

    (what I have included above is the bare minimum for adding an assignment).

    Hope this helps,


    120811049008

    • Marked as answer by tatiana obrien Thursday, August 28, 2014 12:13 AM
    Monday, August 25, 2014 4:42 PM
  • thank you Paul!

    tatiana

    Thursday, August 28, 2014 12:13 AM