none
Changing custom project field value in OnUpdating event RRS feed

  • Question

  • Hi everbody,

    I need to update a project custom field every time a project is saved from PWA on Project Server 2010. My idea was to implement a project OnUpdating event handler that modifies the project dataset before it is saved in the DB but it seems the changes do not have any effect on the project.

    Here is my code:

    public override void OnUpdating(PSContextInfo contextInfo, ProjectPreEventArgs e)
            {
                Guid customFieldGuid = new Guid("xxxxxxxxxxxxxxxxxx");
    
                for (int i = 0; i < e.ProjectDataSet.ProjectCustomFields.Count; i++)
                {
                    if (e.ProjectDataSet.ProjectCustomFields[i].MD_PROP_UID == customFieldGuid)
                    {
                        e.ProjectDataSet.ProjectCustomFields[i].FLAG_VALUE = true;
                        break;
                    }
                }
                e.Cancel = false;
            }

    As you can see the code is quite short and it seems to work. If I debug it and look at the dataset in Visual Studio I can see the changed custom field value but the value is still not saved to the DB. Is what I am trying to do here even possible? Did I forget something important? What is the preferred way to do what I am trying to accomplish?

    Thanks in advance,

    Michael


    • Edited by W_Michael Tuesday, July 24, 2012 12:44 PM
    Tuesday, July 24, 2012 12:41 PM

All replies

  • You cannot change the dataset in the OnUpdating event - or better to say, it will not end up in the database as the dataset that is being presented to you is a kind of copy of the one that is already queued to be sent to the database. Cancelling the event will cause the queued OnUpdate method to be aborted. So much for the architecture of eventing.

    The only thing you can do, is to queue an additional update with your changes - with all the callenges of getting hold of the session and avoiding endless loops.

    So you really need to check for your real requirement to check if you can take a different route to accomplish your functional needs.


    Jan Cirpka

    Tuesday, July 24, 2012 6:12 PM
  • I suspected that it is not possible to change the project dataset in an OnUpdating event handler.
    Thanks for confirming that.

    Unfortunately the official documentation (for PS 2007) is not quite clear on that.

    My functional requirement is to flag projects that have been edited. I guess the best way to accomplish this is to use the OnUpdated event and save the information to an external datasource.

    Thanks again for your help,

    Michael

    Wednesday, July 25, 2012 7:37 AM
  • Would the LastModified date help?


    Jan Cirpka

    Thursday, July 26, 2012 7:42 AM
  • Sorry for the late reply but since I need to be able to query that information in the Project Client (VBA) and direct access to the Project Server DB is prohibited.
    So I do not think that would be a feasible solution.

    I also tried using the "LastSaveDate" and the "CreationDate" of the project object but it seems that the "CreationDate" just holds the date without the time part.

    Thursday, August 2, 2012 7:45 AM