none
Update a Project on Project Published Event RRS feed

  • Question

  • I wanted to know if its possible and if anyone has any examples on how to do the following:

    We want to update a field when a task has been completed, 100%.

    So we thought we can create an Event OnPublishing and update the field if the task is 100% complete.

    Is this possible? Can we grab the workingstore of the project and update the task level field?


    Friday, December 11, 2015 7:24 PM

Answers

All replies

  • Hi,

    I'm not sure there is a BeforePublish event. I've looked in Project and MSDN.

    Simplest is to catch the before save event. What exactly do you want to save where? Its possible a formula can do what you want.


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Sunday, December 13, 2015 10:14 AM
    Moderator
  • Hi Rod, 

    The requirement is to set a custom field to "Today" once a task is 100% complete.

    I was hoping we could override the Project Publishing Event and set the custom field to "Today" but it looks like this is not possible and we would have to wait for the project to get published, check it out again make the changes then check it back in. 


    Sunday, December 13, 2015 6:23 PM
  • BeforeSave event is much the same as the required before publish as you have to save to publish.

    Try:

    Private Sub Project_BeforeSave(ByVal pj As Project)
    Dim Tsk As Task
    For Each Tsk In pj.Tasks If Not Tsk Is Nothing Then If Tsk.PercentComplete = 100 And Tsk.Date1 = "NA" Then Tsk.Date1 = Now End If End If Next Tsk End Sub


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Monday, December 14, 2015 3:30 AM
    Moderator
  • Thanks Rod, 

    This makes complete sense to me. Just one question though, if a user was using the online version of Project Server to update their tasks would this Marco run?

    I think most of the users will be using the client version but I wanted to plan for both scenarios.

    Monday, December 14, 2015 4:07 AM
  • If you need this functionality to work for PWA users as well, you will either have to:

    1. Implement the logic as an enterprise custom field formula (as has been suggested before). THIS IS THE BETTER OPTION. Or

    2. Implement an OnSaved server-side-event-handler that will check out the project and update it on it's own process. It needs to happen "after" the save, you cannot modify a value in the project dataset in the "OnSaving" event handler. From PWA's perpective, you will probably have to wait a bit and then "refresh" the page to see the changes. It's not an optimal solution. I also worry about the "publish" interfering with the "update" you will do from the event handler. 

    Monday, December 14, 2015 5:43 PM
  • Hi Carlos,

    If we use a formula can we set a field? The requirement is that if a task is set to 100% we want to capture the date it happened.

    Monday, December 14, 2015 9:45 PM
  • The formula itself would evaluate to what you want, it does not need to "set" another field. Here's a quick task level formula you can use to start playing with:

    IIf([% Complete] = 100, Date(), "NA")

    Set that to a task level custom field with the name of your choice.

    You will have to handle some edge cases and maybe have to accept some compromises, but I think it gets you 90% of the way there. And this works for PWA too, I just tested it.

    Monday, December 14, 2015 11:00 PM
  • Hi Carlos, 

    I see how this can be helpful but this would mean that a task that is 100% complete today would keep updating everyday so the same task would say it was completed a week from when the task was actually complete, because thats how the formula works.

    Monday, December 14, 2015 11:18 PM
  • Good point. So the custom formula way won't work because what you are trying to capture is a date of when something happened.

    For this you will need a snapshot of some sort.

    Have thought about handling this at the database layer? Basically you can run a SQL job on the reporting DB at regular intervals to check for 100% tasks and store them into a custom table along with today's date. If a task already has a date, of course you would not update it anymore.

    Monday, December 14, 2015 11:46 PM
  • I think a simple VBA macro in the Enterprise Global is a far simpler solution. Yes that does work with Online, I've done macros for Online setups a number of times.

    Don't develop the macro in the Enterprise Global, get it working in a local .mpp file then copy to the Enterprise Global once working. That way you have a backup copy and no chance of corrupting or messing up the Enterprise Global.


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Thursday, December 17, 2015 8:46 PM
    Moderator
  • Rod,

    If I understand the author correctly, the VBA macro solution will not work for him because he wants this to field to be updated even if the edit happens on the PWA. So it's not an OnPrem vs Online situation, it's a Project Pro vs PWA issue.

    Friday, December 18, 2015 3:15 PM
  • OK, so VBA doesn't work and you will have to write some CSOM code (PSI is not supported for the future) though I'm not sure you can do what you need with Online. That functionality is pretty close to the boundary between Online and on prem.

    Your solution will take time and be expensive compared to my VBA solution, so ask the client if they really need it for edits online as well.


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Saturday, December 19, 2015 3:26 AM
    Moderator
  • We ended up creating an event receiver to do this.

    Thanks guys!

    • Marked as answer by spartan422 Wednesday, December 30, 2015 3:59 AM
    Wednesday, December 30, 2015 3:59 AM