0

I am working on OnPublished event handler that will update one custom field of a project based on change in another field.

I am getting an error

Event Handler for event \ProjectPublished\ of type \PS.UpdateProjectStatusChangeDate.EventHandlerUpdateField\ threw an exception: ProjectServerError(s) LastError=CICOCheckedOutToOtherUser Instructions: Pass this into PSClientError constructor to access all error information

This is the code

        //loading project data from server
        //Every change on this dataset will be updated on the server!
        ProjectDataSet projectDs = projectClient.ReadProject(projectId, projectSvc.DataStoreEnum.WorkingStore);

        foreach (projectSvc.ProjectDataSet.ProjectRow row in projectDs.Project)
        {
            if (row.PROJ_SESSION_UID != null)
            {
                sessionId = row.PROJ_SESSION_UID;
                break;
            }
        }
       //send the dataset to the server to update the database
       bool validateOnly = false;
       Guid jobId = Guid.NewGuid();
       projectClient.QueueUpdateProject(jobId, sessionId, projectDs, validateOnly);

Unlike other answers where we are running the code when the project is in checked-in state, we are checking-out and assigning new SessionID. But when the event handler fires, the project is already is checked-out. So how do I get the SessionID. I think that is where the code is breaking.

sid1385
  • 65
  • 2
  • 13

1 Answers1

0

Logically that makes sense. While project is checked out that means that somebody can change it at any time and in any way.

So even if your idea works your update can be overwritten by the next save done from Project Pro. Because Project Pro knows nothing about your manipulations.

I don't know anything about your system so let me guess that your users work with Project Pro mostly. In this case you can add your event handler to Application.ProjectBeforePublish msdn link event and update the field from Project Pro. But please keep in mind that your users will be asked to save the project before publishing.

If the solution with Project Pro does not work for you - you can flag published projects somehow and as soon as the project is checked in - do check out, update the field, save and publish the project again.

melan
  • 1,688
  • 1
  • 11
  • 8
  • Thanks for the answer @melan. Users, in my case uses, both Project Pro and PWA like 50-50. Setting a flag for the published project - this thing has crossed my mind, but never found any way to do it. – sid1385 Mar 05 '13 at 12:56