Create task in existing MSP project using PSI

1.9k views Asked by At

I am trying to create a task in an existing project via PSI using the code provided my MSDN: http://msdn.microsoft.com/en-us/library/office/ms487478(v=office.12).aspx#pj12_PDSPSIExamples_Task

The problem is I am getting error "GeneralOnlyUpdatesAllowed", when trying to call projectClient.QueueUpdateProject(jobId, sessionId, project, false);

Any ides?

 Guid sessionId = Guid.NewGuid();
            Guid jobId = Guid.NewGuid();
            string SESSION_DESC = "MSP-DAX Synchronization";                
            backendProject.ProjectDataSet project = projectClient.ReadProject(task.ProjectId, backendProject.DataStoreEnum.WorkingStore);                   
            projectClient.CheckOutProject(task.ProjectId, sessionId, SESSION_DESC);
            backendProject.ProjectDataSet.TaskRow taskRow = project.Task.NewTaskRow();
            taskRow.PROJ_UID = task.ProjectId;
            taskRow.TASK_UID = Guid.NewGuid();
            taskRow.TASK_NAME = task.Subject;
            taskRow.CREATED_DATE = task.Date;
            taskRow.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Hour;          
            project.Task.AddTaskRow(taskRow);                            
            projectClient.QueueUpdateProject(jobId, sessionId, project, false);//here is the error
            //projectClient.QueueAddToProject(jobId, sessionId, project, false);
            WaitForQueue(queueSystemClient, jobId);
            jobId = Guid.NewGuid();
            projectClient.QueueCheckInProject(jobId, task.ProjectId, false, sessionId, SESSION_DESC);
            WaitForQueue(queueSystemClient, jobId);
1

There are 1 answers

0
Vahagn Nahapetyan On BEST ANSWER

Strange behaviour, but any way. I changed the following rows :

backendProject.ProjectDataSet project = projectClient.ReadProject(task.ProjectId,            backendProject.DataStoreEnum.WorkingStore);
projectClient.QueueUpdateProject(jobId, sessionId, project, false);

with these ones:

backendProject.ProjectDataSet project = new backendProject.ProjectDataSet();
projectClient.QueueAddToProject(jobId, sessionId, project, false);

and all worked. Looks like you can add task only to not initialized project.