How to get old/previous value of Project Name when changed?

Answered How to get old/previous value of Project Name when changed?

  • 11/جمادى الثانية/1433 06:26 ص
     
     

    I have a requirement to trigger a email notificaiton if Project Name and/or Project Owner are change. I am struggling to get the previous value of Project Name and for the Project Owner i can't get the new value when i change it.

    e.ProjectName is always the new value

    This code to get the Project Owner Id always gets the old values (via PSI on Working Store and PublishStore)

    ProjectSvc.ProjectDataSet pubsStoreProjectDS = project.ReadProject(e.ProjectGuid, ProjectSvc.DataStoreEnum.PublishedStore); string NewProjectOwner = pubsStoreProjectDS.Project[0].ProjectOwnerID.ToString();

    I was able to do this on custom fields [GetChanges] method in project updating server event, but not on Project Name and Project Owner.

    Any advise on how to acheive this? 

    Thanks.

    Rupert


    • تم التحرير بواسطة RupertJM 11/جمادى الثانية/1433 06:33 ص
    •  

جميع الردود

  • 11/جمادى الثانية/1433 06:46 ص
     
      يتضمن تعليمات برمجية

    Hi There--

    You can get the OnSave/published/Updated event handler of project server. Since you knwo the projectuid, get the project name & ownername from Reporting database & compare the values with contextInfo, if you see the mismatch, trigger an email or any action required.

    geenral info on PS event hanlders:
    http://technet.microsoft.com/en-us/library/gg982976.aspx

    public virtual void OnSaved(
    	PSContextInfo contextInfo,
    	ProjectPostEventArgs e
    )

    // Get information from the event arguments.

    // Get information from the event arguments.
            string userName = contextInfo.UserName;
            Guid pwaUid = contextInfo.SiteGuid;
            string projectName = e.ProjectName;
            Guid projectUid = e.ProjectGuid;
            PSSchema.ProjectDataSet projDs = e.ProjectDataSet;

    http://msdn.microsoft.com/en-us/library/gg205991.aspx

    http://msdn.microsoft.com/en-us/library/gg607685.aspx

    Getting Started with Development for Project 2010:
    http://msdn.microsoft.com/en-us/library/gg615466.aspx

    You can also get the sample of Event handlers from project 2010 SDK.
    http://www.microsoft.com/en-us/download/details.aspx?id=15511

    Hope that helps.


    Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

  • 12/جمادى الثانية/1433 11:36 ص
     
     
    Thanks for your reply Amit. I've tried what you've suggested but i'm getting an error when trying to read on Report Store.

    public override void OnUpdated(PSContextInfo contextInfo, ProjectPostUpdatedEventArgs e)
       
    ProjectSvc.ProjectDataSet reportStoreProjectDS = project.ReadProject(e.ProjectGuid, PWAProjectSvc.DataStoreEnum.ReportingStore);

    Error:

    Name: Project Server Service Application PSError: GeneralInvalidDataStore (80)
    Operation failed because the data store you are trying to refer to is invalid - it is neither the Draft data store nor the Published data store.

    Also the contextinfo you mentioned is not the old value its the new value that i just entered. So to think about it, since this is OnUpdated event the values retrieved regardless of datastore will always be the new value and this will not achieve my expected result.

    btw, how do you read RDB? Maybe the way i'm reading RDB is not correct that is why i'm getting an exception.

    Thanks again.
    Rupert
    • تم التحرير بواسطة RupertJM 12/جمادى الثانية/1433 11:38 ص
    •  
  • 12/جمادى الثانية/1433 11:43 ص
     
      يتضمن تعليمات برمجية

    Hi There,

    A Simple way to read the RDB data is create a Stored proc in that which gets the Projectuid as a parameter & gets you the desired info in datatable. Once you get the data, You can compare the values. You can call the SP from your code OnSave event handler.

    A simple SQL query where you get all Project Name, Ownername & UID etc

    select ProjectUID, ProjectName, ProjectOwnerName,ProjectOwnerResourceUID from dbo.MSP_EpmProject_UserView
    Hope that helps.

    Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

  • 24/جمادى الثانية/1433 05:41 ص
     
     الإجابة يتضمن تعليمات برمجية

    Just to close this thread.

    As i understand how event handler works this is a simple requirement with a simple solution: Here it is

    public class MyEventHandler : ProjectEventReceiver
    {
    public override void OnUpdating(PSContextInfo contextInfo, ProjectPreEventArgs e)
    {
    //Get new project name
    string newProjectName = e.ProjectName.ToString();
    //Get old project name
    string oldProjectName="";
    ProjectSvc.ProjectDataSet pubsStoreProjectDS = project.ReadProject(e.ProjectGuid, ProjectSvc.DataStoreEnum.PublishedStore);
     if(!pubsStoreProjectDS.Project[0].IsPROJ_NAMENull())
                      oldProjectName = pubsStoreProjectDS.Project[0].PROJ_NAME.ToString();
    //Compare the pair
     if (oldProjectName != newProjectName)
       //Send email notification here
    }
    }

    • تم وضع علامة كإجابة بواسطة RupertJM 24/جمادى الثانية/1433 05:42 ص
    •