Answered by:
assign resources to a task programmatically

Question
-
hello forum members,
does anyone knows which field in "Assignment" table in Project dataset belongs to a resource name assigned to a task?
below is my code and I see a guid added in "RES_UID_OWNER" AND "RES_UID", but when I open this project in Project Server or Project 2013 - I don't see resources assigned to a task.
Any help is appreciated.
backendProject.ProjectDataSet readProjDs = projectClient.ReadProjectEntities(projectUids, PROJECT_ENTITY_TYPE_TASK_AND_RESOURCE, backendProject.DataStoreEnum.WorkingStore);
backendProject.ProjectDataSet.AssignmentRow newAssignmentRow = readProjDs.Assignment.NewAssignmentRow();
Guid RES_UID = new Guid("a153f98d-3b7e-e311-aa5f-0050569d03ac"); //get resource id
newAssignmentRow.ASSN_UID = Guid.NewGuid();
try
{
Guid newGuid = Guid.Parse(taskid);
Console.WriteLine("Converted {0} to a Guid", taskid);
newAssignmentRow.TASK_UID = newGuid; //get the task id
}
catch (ArgumentNullException)
{
Console.WriteLine("The string to be parsed is null.");
}
catch (FormatException)
{
Console.WriteLine("Bad format: {0}", taskid);
}
newAssignmentRow.PROJ_UID = projectUids;
newAssignmentRow.RES_UID = RES_UID;
newAssignmentRow.RES_UID_OWNER = RES_UID;
newAssignmentRow.ASSN_START_DATE = DateTime.Now;
newAssignmentRow.ASSN_FINISH_DATE = DateTime.Now.AddDays(2);
readProjDs.Assignment.AddAssignmentRow(newAssignmentRow);
//check the project back in
projectClient.QueueCheckInProject(jobId, projectUids, false, sessionId, SESSION_DESCRIPTION);
tatiana
Tuesday, September 2, 2014 9:07 PM
Answers
-
Okay, error rings some bells, i think you will need to use statusing WCF in order to create assignment, with project you can only update an assignment i believe
try using the statusingClient.CreateNewAssignment() method
Thanks | epmXperts | http://epmxperts.wordpress.com
- Marked as answer by tatiana obrien Friday, September 5, 2014 5:50 PM
Friday, September 5, 2014 1:11 PM -
thanks epmEperts!
that was very helpful. I looked up statusing here: http://msdn.microsoft.com/en-us/library/office/gg240915(v=office.15).aspx
and looks like i forgot to include 2 lines. I still used my old code , plus the following:
// Get only the added rows
readProjDs = (SvcProject.ProjectDataSet)readProjDs.GetChanges(DataRowState.Added);
//add to project
projectClient.QueueAddToProject(jobId, sessionId, readProjDs, false);tatiana
- Marked as answer by tatiana obrien Friday, September 5, 2014 5:50 PM
Friday, September 5, 2014 5:50 PM
All replies
-
I may be wrong, but in your code, i don't see projectClient.QueueUpdate() method, before checking i believe you need to update your project in order to save the assignment update
Thanks | epmXperts | http://epmxperts.wordpress.com
Thursday, September 4, 2014 6:11 PM -
thanks epmXperts,
i already tried that and i was getting an error : " ProjectServerError(s) LastError=GeneralOnlyUpdatesAllowed Instructions: Pass this into PSClientError constructor to access all error information"
this was my code
//update project
projectClient.QueueUpdateProject(jobId, sessionId, readProjDs, false);
//check the project back in
projectClient.QueueCheckInProject(jobId, projectUids, false, sessionId, SESSION_DESCRIPTION);
tatiana
- Edited by tatiana obrien Thursday, September 4, 2014 10:15 PM
Thursday, September 4, 2014 10:14 PM -
Okay, error rings some bells, i think you will need to use statusing WCF in order to create assignment, with project you can only update an assignment i believe
try using the statusingClient.CreateNewAssignment() method
Thanks | epmXperts | http://epmxperts.wordpress.com
- Marked as answer by tatiana obrien Friday, September 5, 2014 5:50 PM
Friday, September 5, 2014 1:11 PM -
thanks epmEperts!
that was very helpful. I looked up statusing here: http://msdn.microsoft.com/en-us/library/office/gg240915(v=office.15).aspx
and looks like i forgot to include 2 lines. I still used my old code , plus the following:
// Get only the added rows
readProjDs = (SvcProject.ProjectDataSet)readProjDs.GetChanges(DataRowState.Added);
//add to project
projectClient.QueueAddToProject(jobId, sessionId, readProjDs, false);tatiana
- Marked as answer by tatiana obrien Friday, September 5, 2014 5:50 PM
Friday, September 5, 2014 5:50 PM