miércoles, 2 de abril de 2008

Create a task assignment

Hi again,
Today I'm going to explain how to create a resource asignment and a cost assignment to a task using PSI.

Variables
ProjWS --> project web service initialized
proyectoid --> GUID of the project


1. First of all we need to get the ProjectDataSet of our project.

ProjectDataSet dsNew = projWS.ReadProject(proyectoid, Project.DataStoreEnum.WorkingStore);

2. Create a new Assignment row in the project

Project.ProjectDataSet.AssignmentRow ResRow = dsNew.Assignment.NewAssignmentRow();

3. Make the assignment between the user and the task

ResRow.PROJ_UID = projectUid; //GUID of the project
ResRow.ASSN_UID = Guid.NewGuid();
ResRow.RES_UID = resUid; // GUID of the resource
ResRow.RES_TYPE = AssignmentType; //Type of assignment
ResRow.TASK_UID = taskUid; //GUID of the task

4. Add the assignment cost if is a cost resource
if ( AssignmentType= 25) {
ResRow.ASSN_COST = ResourceCost;
}

5. Add the new Assignment row to the ProjectDataSet and add it to the project

dsNew.Assignment.AddAssignmentRow(ResRow);
Guid jobGuid = Guid.NewGuid();
projWS.QueueAddToProject(jobGuid, sessionGuid, dsNew, false);

2 comentarios:

Jorge Flor dijo...

Buenas! he seguido tu código para crear una asignación y me ha salido la siguiente excepción: GeneralOnlyUpdatesAllowed.
con el QueueAddToProject me sale la expcepción: GeneralOnlyInsertsAllowed

Mi código es el siguiente:

dsNew = projectWS.ReadProject(projectUID, DataStoreEnum.WorkingStore);

Guid jobGuid = Guid.NewGuid();
Guid sessionGuid = Guid.NewGuid();

//Create a new Assignment row in //the project ProjectDataSet.AssignmentRow ResRow = dsNew.Assignment.NewAssignmentRow();

ResRow.PROJ_UID = projectUID; ResRow.ASSN_UID = Guid.NewGuid();
ResRow.RES_UID = resUID; ResRow.RES_TYPE = 2; ResRow.TASK_UID = taskUID;
dsNew.Assignment.AddAssignmentRow(ResRow);

projectWS.QueueUpdateProject(jobGuid, sessionGuid, (ProjectDataSet)dsNew.GetChanges(), false);
//sin GetChanges() también falla
WaitForQueue(queueWS, jobGuid);

Alguna posible solución??

Un saludo,

Jorge.

Anónimo dijo...

Problamemente se debe a que el proyecto debe estar en checkout.