none
Project Server 2010: populating a custom field using an event handler RRS feed

  • Question

  • Hi,

    i'm new to project server programming and i have been trying to find a way to populate a custom field when a project is created.

    I'm using an OnCreated Event handler and have tried the following:

    WebSvcProject.

    ProjectDataSet prjDS = prjSvc.ReadProject(e.ProjectGuid, WebSvcProject.DataStoreEnum

    .WorkingStore);

     

    foreach (WebSvcProject.ProjectDataSet.ProjectCustomFieldsRow cfRow in

    prjDS.ProjectCustomFields)

    {

     

    if

    (cfRow.MD_PROP_UID == CustomFieldGuid)

    {

    cfRow.TEXT_VALUE =

    "Custom Value goes here"

    ;

     

    break

    ;

    }

    }

    I tried outputting the projectdataset to an XML file and the field i want to populate is not listed in the projectcustomfields available. I have checked in pwa server settings and the custome field is set as a project level field.

    Any ideas what i am doing wrong, or if i'm going about this the wrong way how should this be done?

    Thanks

    Andy

    Thursday, May 19, 2011 4:35 PM

Answers

  • Hi Andy,

    Unless you add a Project custom field when the project is created, for example by configuring the CF definition in PWA to choose a lookup table value as a default, or by specifically adding the CF, no Project CF row will exist in the ProjectCustomFields data.

    In the Project Created event handler, check the project out, add the custom field by using QueueUpdateProject, and then check the project back in.

    --Jim


    Jim Corbin [MSFT]
    • Marked as answer by lawes_a Friday, May 20, 2011 3:19 PM
    Thursday, May 19, 2011 8:54 PM

All replies

  • Hi Andy,

    Unless you add a Project custom field when the project is created, for example by configuring the CF definition in PWA to choose a lookup table value as a default, or by specifically adding the CF, no Project CF row will exist in the ProjectCustomFields data.

    In the Project Created event handler, check the project out, add the custom field by using QueueUpdateProject, and then check the project back in.

    --Jim


    Jim Corbin [MSFT]
    • Marked as answer by lawes_a Friday, May 20, 2011 3:19 PM
    Thursday, May 19, 2011 8:54 PM
  • Hi,

      I was having the same problem so I followed your instructions. However, I can't check out the project in OnCreated event. It throws an exception "ProjectServerError(s) LastError=CICOCheckedOutInOtherSession Instructions: Pass this into PSClientError constructor to access all error information". Any help would be appreciated.

    ~ Ahmed

    Wednesday, February 29, 2012 11:26 AM
  • You've run into a little challenge for which I am still looking for a solution. The reason is, that any update on the dataset that is passed to you in an event will not be persisted. In Pre-events you can cancel if custom business rules require this, in Post-events you can do additional work. The Pre-event does not allow you to modify the dataset that is about to be persited. All you can do is 'additional work' - in your case a subsequent save.

    To save the project must be checked out, but as you noticed - your project is already being checked out by the end-user. You would need to get hold of the session - but that is as fyour update using the same session. In other words your additional save is added to the session. But even if you have accomplished this I am not sure if the user could not have checked in the project before your queued save operation is been handled. That is as the Checkin is also a queue message - your's may just be queued after this one. With the create though this seems unlikely.


    Jan Cirpka

    • Proposed as answer by A Salam Saturday, March 3, 2012 3:56 PM
    Thursday, March 1, 2012 8:52 AM
  • Hi Jan,

    Thank you for you reply. I have been struggling with this for the past couple of days and came to the very same conclusion. Could you tell me which event I may use to set a project custom field value, if not create?

    If its not possible through event handlers, what could be the best solution? Many thanks in advance.

    ~ Ahmed

    Friday, March 2, 2012 8:23 AM