How to get Custom Field old value using Server Event Handler?

Answered How to get Custom Field old value using Server Event Handler?

  • 2012. április 19. 5:54
     
     

    Hi Guys,

    I have a requirement in Project Server 2010 to trigger an email if a custom field is updated. I've looked at Project Updating Server Event but i'm struggling to check how to get old/current values from custom fields so i can differentiate and send an email if these values are changed. Or is there a better approach other than Server Event Handler?

    Please advise.

    Thanks

     

Az összes válasz

  • 2012. április 19. 11:39
     
      Kódot tartalmaz
    Have you considered to retrieve the project from the working store. It is (yet) unchanged, so you can compare. See some code snipped below

    public override void OnUpdating(PSContextInfo contextInfo, UpdatingProjectEventArgs e) { ProjectDataSet workingStoreProjectDataSet = ProxyHelper.ProjectProxy.ReadProject(projectguid, DataStoreEnum.WorkingStore); // There should be only one dataset foreach (var projectDataSet in e.ProjectUpdates) { ProjectUpdatesDataSet.ProjectRow projectWithChanges = null; ProjectDataSet.ProjectRow workingStoreProject = null; if (projectDataSet.Project.Count > 0) { projectWithChanges = projectDataSet.Project[0]; } if (workingStoreProjectDataSet.Project.Count > 0) { workingStoreProject = workingStoreProjectDataSet.Project[0]; } }



    Jan Cirpka


  • 2012. április 22. 5:51
    Moderátor
     
     Javasolt válasz

    I would suggest Server Side Event Handlers are definately the way to go.

    I have done it in the past using an event handler on the Project > Save or Project > Published events and written the values out to a SharePoint list or custom DB. From there you can compare the current value with the past value and raise a notification if necessary. An advantage of this approach is you also get an audit trail / report as a by product.


    Alex Burton
    www.epmsource.com | Twitter
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page

  • 2012. május 2. 4:48
     
     Válasz

    Thanks for the response guys! Sorry it took me a while, I've tried reading it from a database but i'm getting an error saying 'server could not be found or you don't have enough permission' and i'm pretty sure i've got enough permission and the server is online and i'm using the same function i've use on implementing my webpart...anyway what i'm ending up doing is this on void OnUpdating(PSContextInfo contextInfo, ProjectPreEventArgs e):

    DataSet changeDataSet = e.ProjectDataSet.GetChanges(DataRowState.Modified|DataRowState.Added);
                   string cfuid = "";
                   foreach (DataTable table in changeDataSet.Tables)
                   {
                       foreach (DataRow row in table.Rows)
                       {
                           foreach (DataColumn column in table.Columns)
                           {
                              
                            cfuid = row["MD_PROP_UID"].ToString();
                               if (cfuid == [MyCustomFieldUID])
                               {
                                   MyCFNewValue = row["TEXT_VALUE"].ToString();
                                   break;
                               }
                           }
                       }
                   }

    Sorry Jan, i've tried your code and its not working. My intellisense doesn't recognise UpdatingProjectEventArgs.

    And to get the old value

    ProjectSvc.ProjectDataSet workStoreProjectDS = project.ReadProject(e.ProjectGuid, PWAProjectSvc.DataStoreEnum.WorkingStore);
                   ProjectSvc.ProjectDataSet.ProjectCustomFieldsRow OldResult = (from ProjectSvc.ProjectDataSet.ProjectCustomFieldsRow customField in workStoreProjectDS.ProjectCustomFields.AsEnumerable()
                                                                                    where customField.MD_PROP_UID == MyCustomFieldUID
                                                                                    select customField).SingleOrDefault();
                   string MyCFOldValue = OldResult.TEXT_VALUE;

    Next challenge is how to determine via Event Handler  the changes made on a Project Name and Project Owner (this is not a custom field). Any advise?

    Thanks

    Rupert

    • Megjelölte válaszként: RupertJM 2012. május 2. 4:48
    •