none
Updating values for External Task by getting its ID RRS feed

  • Question

  • Hello,

    We are running Project Server 2019 and MS Project 2019.

    We are running Project VBA and I want to set values to the External Task Successor in the Active Project. We have set 6 fields to be received by the External Task Predecessor and set it in the External Task Successor.

    External Tasks

    So I wanted to have values of External Predecessor for e.g. 18-12-2019, 26-12-2019 to be stored in External Successor tasks values. Similarly for the Task Name, Project Name, Percentage Completion and Health needs to be stored from External Predecessor in to External Successor. So that we will have values in the REST Api for a particular project.

    The purpose behind this is to show in the custom dashboard using ASP.Net and REST Api, the dependency management where XY project is linked to AB project with these many tasks etc.

    Regards


    Tanzim Akhtar


    • Edited by Tanzim Tuesday, December 31, 2019 12:16 PM REST Api info
    Tuesday, December 31, 2019 12:12 PM

Answers

  • Tanzim,

    The vba block below may get you started....  It copies specific data from external predecessors to custom fields of their successors in the active project.

    1. External tasks (sometimes called "ghost tasks") provide a basis for visual reference in the active project.  They contain some (not all) data from the tasks in their source projects.  I've not seen a good list of such data, but they are generally read-only.  They may or may not be fully updated.

    2. Custom field values of a task in a source project are not transferred to the corresponding external task in another project.  If "Health" is such a field, then you will need to recompute it for the external task in the new project (maybe using a custom field formula).  Alternately, you can find and refer to the source data directly in your code - that's a different animal.     

    Good luck, tom

    Sub CopyExternalPredecessorFields() Dim pt As Task Dim st As Task For Each pt In ActiveProject.Tasks If Not pt Is Nothing Then If pt.ExternalTask Then For Each st In pt.SuccessorTasks 'st.Text10 = pt.Project st.Text10 = pt.Parent.Name st.Text11 = pt.Name st.Number10 = pt.PercentComplete st.Date1 = pt.Start st.Date2 = pt.Finish

    'The following statement presumes that Text12 of the external task

    'has been computed from other data of the task.

    st.Text13 = pt.Text12 Next st End If End If Next pt End Sub


    • Marked as answer by Tanzim Wednesday, January 1, 2020 8:16 AM
    Tuesday, December 31, 2019 5:35 PM

All replies

  • Tanzim,

    The vba block below may get you started....  It copies specific data from external predecessors to custom fields of their successors in the active project.

    1. External tasks (sometimes called "ghost tasks") provide a basis for visual reference in the active project.  They contain some (not all) data from the tasks in their source projects.  I've not seen a good list of such data, but they are generally read-only.  They may or may not be fully updated.

    2. Custom field values of a task in a source project are not transferred to the corresponding external task in another project.  If "Health" is such a field, then you will need to recompute it for the external task in the new project (maybe using a custom field formula).  Alternately, you can find and refer to the source data directly in your code - that's a different animal.     

    Good luck, tom

    Sub CopyExternalPredecessorFields() Dim pt As Task Dim st As Task For Each pt In ActiveProject.Tasks If Not pt Is Nothing Then If pt.ExternalTask Then For Each st In pt.SuccessorTasks 'st.Text10 = pt.Project st.Text10 = pt.Parent.Name st.Text11 = pt.Name st.Number10 = pt.PercentComplete st.Date1 = pt.Start st.Date2 = pt.Finish

    'The following statement presumes that Text12 of the external task

    'has been computed from other data of the task.

    st.Text13 = pt.Text12 Next st End If End If Next pt End Sub


    • Marked as answer by Tanzim Wednesday, January 1, 2020 8:16 AM
    Tuesday, December 31, 2019 5:35 PM
  • Thank you Tom for the reply.

    I have to see how to fill-in the two fields namely, Project Name and Health, rest everything gets filled-in by your code.

    Regards


    Tanzim Akhtar


    • Edited by Tanzim Thursday, January 2, 2020 7:07 AM
    Wednesday, January 1, 2020 8:16 AM
  • Tanzim,

    I'm glad you got that part worked out.  Regarding the external task project name, I would expect the commented-out statement to work: st.Text10 = pt.Project, though you may need to use some string functions to trim the result.  In a non-PS environment, the task.Project attribute can come with a long path prefix, and I tried using the task.parent.name attribute as an alternative.

    Good luck, tom

    Wednesday, January 1, 2020 5:54 PM
  • Tom,

    We did it in a different way as follows:

    Sub ExternalTaskInfo()
    Dim tsk As Task
    Dim tsk1 As Task
    Dim extStart
    Dim extFinish
    Dim extComplete
    Dim extName
    Dim extProjectName
    Dim extHealth
    Dim arrProjectName() As String
    
    extStart = FieldNameToFieldConstant("External Task Start", pjTask)
    extFinish = FieldNameToFieldConstant("External Task Finish", pjTask)
    extComplete = FieldNameToFieldConstant("External Task Percent", pjTask)
    extName = FieldNameToFieldConstant("External Task Name", pjTask)
    extProjectName = FieldNameToFieldConstant("External Task Project Name", pjTask)
    extHealth = FieldNameToFieldConstant("External Task Health", pjTask)
    
        For Each tsk In ActiveProject.Tasks
            If Not tsk Is Nothing Then
                If tsk.ExternalTask Then
                
                    For Each tsk1 In tsk.SuccessorTasks
                        tsk1.SetField FieldID:=extStart, Value:=tsk.Start
                        tsk1.SetField FieldID:=extFinish, Value:=tsk.Finish
                        tsk1.SetField FieldID:=extComplete, Value:=tsk.PercentComplete
                        tsk1.SetField FieldID:=extName, Value:=tsk.Name
                        
                        arrProjectName() = Split(tsk1.Predecessors, "\")
                        
                        tsk1.SetField FieldID:=extProjectName, Value:=arrProjectName(1)
                        tsk1.SetField FieldID:=extHealth, Value:=tsk.Health
                    Next tsk1
                End If
            End If
        Next tsk
    
    
    End Sub
    

    Regards


    Tanzim Akhtar

    Thursday, January 2, 2020 6:50 AM