none
How to add a Task Resource Assignment using PSI RRS feed

  • Question

  • hey, I am struggling with adding a resource assignment to a task and need help. desperately! ahhhh!

    okay, so I have projtool so I have a good framework of examples, but I'm just getting generic queue failed when trying to do an update. here is a basic idea of my code below. do I need to do something special or am I missing some references that are required when adding an assignment? everything is working til I add an assignment row.

    foreach (var activity in task.Activities)
    {
        var activityRow = insertDataSet.Task.NewTaskRow();
     
        activityRow.PROJ_UID            = projectGuid;
        activityRow.TASK_UID            = Guid.NewGuid();
        activityRow.TASK_NAME           = string.IsNullOrEmpty(activity.Name) ? activity.Description : string.Format("{0} - {1}", activity.Name, activity.Description);
        activityRow.TASK_OUTLINE_LEVEL  = indent+1;
        activityRow.TASK_WBS            = activity.Name;
        activityRow.AddPosition         = 1;
        activityRow.AddAfterTaskUID     = lastTaskGuid;
     
        insertDataSet.Task.AddTaskRow(activityRow);
                            
        lastTaskGuid = activityRow.TASK_UID;
     
        if (transferOptions.IncludeResourceAssignments)
        {
            foreach (var ra in sourceDocument.ResourceAssignments.GetResourceAssignments(activity.Name))
            {
                var resourceGroup   = sourceDocument.ResourceGroups.GetResourceGroup(ra.ResourceType);
                var resource        = resourceGroup.Resources.GetResource(ra.ResourceID);
                                    
                if (resource == null)
                    continue;
     
                var matchingResources = resourceDataSet.Resources.Select( string.Format("RES_NAME = '{0}'", resource.Name ) );
     
                if( matchingResources != null && matchingResources.Length > 0 )
                {
                    var matchingResource = matchingResources[0];
     
                    var raRow = insertDataSet.Assignment.NewAssignmentRow( );
     
                    raRow.PROJ_UID  = projectGuid;
                    raRow.ASSN_UID  = Guid.NewGuid();
                    raRow.RES_UID   = new Guid("870ead10-c199-4abd-a420-b755140ff886"); // new Guid(matchingResource["RES_UID"].ToString( ));
                    raRow.TASK_UID  = activityRow.TASK_UID;
     
                    ifConvert.ToInt32( matchingResource["RES_TYPE"].ToString( ) ) == 25 )
                        raRow.ASSN_ACT_COST = resource.Rate;
                                            
                    insertDataSet.Assignment.AddAssignmentRow(raRow);
                }
            }
        }
    }
    SvcProject.ProjectDataSet addTasks = new SvcProject.ProjectDataSet();
    addTasks.ProjectResource.Merge(insertDataSet.ProjectResource, true);
    addTasks.Task.Merge(insertDataSet.Task, true);
    addTasks.Dependency.Merge(insertDataSet.Dependency, true);
    addTasks.Assignment.Merge(insertDataSet.Assignment, true);
    addTasks.TaskCustomFields.Merge(insertDataSet.TaskCustomFields, true);
    addTasks = (SvcProject.ProjectDataSet)addTasks.GetChanges(DataRowState.Added);
     
    if (addTasks != null)
       ProjectServerApi.AddToProject(addTasks, sessionGuid);

    • Moved by epmXpertsModerator Wednesday, November 7, 2012 9:40 PM Moving to appropriate forum (From:Project Server General Questions and Answers)
    Tuesday, November 6, 2012 8:32 PM

All replies

  • I have to say, microsoft project server is one of the most poorly written interfaces I have ever seen. I expect far better from microsoft.
    Tuesday, November 6, 2012 9:33 PM
  • whats the error message you are getting in the queue ?

    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com

    Wednesday, November 7, 2012 9:39 PM
    Moderator
  • If you add resources while adding assignments you need to split your calls. Resources are added using UpdateProjectTeam to your project. I never have used any Merge methods on the datasets - basically I  distinguish between updates and new rows and use UpdateProject and AddToProject.

    Jan Cirpka

    Thursday, November 8, 2012 4:17 PM