none
Team Planner and Task ID's RRS feed

  • Question

  • Hi all,

    Does any know if there is a way to extract a task ID from a task while in the Team Planner view? I have written a simple Macro to add and remove Splits to tasks while in the Team Planner but in order for this to run I need to know the task's ID. This involves two approaches:

    1. Opening the Details Split View and searching for the task within the Resource's allocation. Time consuming as most Resources have 100+ tasks allocated to them and there does not seem to be a clear order to the tasks listed.
    2. Returning to the Gannt Chart view and extracting the task ID. Also time consuming and the task in question needs to be isolated.

    Is there any chance of adding the task ID to the Task Information pop up window? Or does anyone have any idea of a macro that could provide a pop up with the task ID?

    Thanks in advance!!

    Thursday, July 11, 2019 4:23 AM

Answers

  • roryTriesVBA,

    I assume you want to find the task ID of a selected task in the Team Planner view. Unfortunately, the Team Planner view does not support active selections.

    You might consider this approach. Select the desired task in the Team Planner view. Then run a macro that asks the user for the task's name and use that with the following statement to get the task ID

    ActiveProject.Tasks("name").ID

    And to answer your question about adding something to the Task Information window, sorry no can do. That is a view/popup internal to the application and are not user modifiable.

    Hope this helps.

    John


    • Edited by John - Project Thursday, July 11, 2019 3:38 PM answer question
    • Marked as answer by roryTriesVBA Friday, July 19, 2019 12:19 AM
    Thursday, July 11, 2019 3:04 PM
  • Thanks for the advice John.

    I followed your general approach with a small tweak. Luckily the SetTaskField method operates on Task objects that are selected in the Team Planner view when the parameter AllSelectedTasks is set to true. I use this method to assign an identity tag in one of the tasks custom fields while in the Team Planner and then have a loop that runs through all the projects tasks, finds this tag and extracts the task's ID from it. This task ID is then used to run the Split method. The VBA code is shown below:

    Sub CreateSplit()
        Dim WhichTask As Long
        Dim t As Task
        Dim ts As Tasks
        Dim commentName As Variant
        Dim taskID As Long
        Dim SplitFrom As Variant, SplitTo As Variant
        Dim splitDuration As Long
        Dim endDate As Variant
        
        Set ts = ActiveProject.Tasks

        SetTaskField Field:="Comments", Value:="selectedTask", AllSelectedTasks:=True
        
        For Each t In ts
            If Not t Is Nothing Then
                If Not t.Summary Then
                commentName = t.GetField(FieldNameToFieldConstant("Comments"))
                    If commentName = "selectedTask" Then
                    taskID = t.GetField(pjTaskID)
                    t.SetField Application.FieldNameToFieldConstant("Comments"), ""
                    End If
                End If
            End If
        Next t

        taskID = CInt(taskID)
        Set t = ActiveProject.Tasks(taskID)
        SplitFrom = InputBox("Enter the date and time for the start of the" & " split: " & vbCrLf & vbCrLf & "(The default time is the end" & " time of the preceding working period. 26/06/19)")
        SplitTo = InputBox("Enter the date and time for the end of the split:" & vbCrLf & vbCrLf & "(The default time is the start time of the next" & " working period. 26/06/19)")
        SplitFrom = SplitFrom & " 6:00 AM"
        SplitTo = SplitTo & " 6:00 AM"
        ActiveProject.Tasks(taskID).Split SplitFrom, SplitTo
        
        SplitFrom = DateValue(SplitFrom)
        SplitTo = DateValue(SplitTo)
        splitDuration = DateDiff("d", SplitFrom, SplitTo) * -1
        endDate = t.GetField(Application.FieldNameToFieldConstant("Finish"))
        endDate = Right(endDate, 8)
        endDate = DateValue(endDate)
        endDate = DateAdd("d", splitDuration, endDate)
        t.SetField Application.FieldNameToFieldConstant("Finish"), endDate
        
        
    End Sub



    Monday, July 15, 2019 1:42 AM
  • roryTriesVBA,

    You're welcome and thanks for the feedback. I'd probably simplify the macro a bit. For example, if your custom field is Text1, your loop could be,

    SetTaskField Field:="Text1", Value:="selectedTask", AllSelectedTasks:=True
        
        For Each t In ActiveProject.Tasks
            If Not t Is Nothing Then
                If Not t.Summary Then
                    If t.Text1 = "selectedTask" Then
                        taskID = t.ID
                        t.Text1 = ""
                        Exit For
                    End If
                End If
            End If
        Next t

    Also, your input boxes ask for a date and time but then the code "resets" the time to 6:00 AM, so why ask for the time.

    Nonetheless, if it's working for you, go with it and give yourself credit.

    John

    Monday, July 15, 2019 2:29 AM

All replies

  • roryTriesVBA,

    I assume you want to find the task ID of a selected task in the Team Planner view. Unfortunately, the Team Planner view does not support active selections.

    You might consider this approach. Select the desired task in the Team Planner view. Then run a macro that asks the user for the task's name and use that with the following statement to get the task ID

    ActiveProject.Tasks("name").ID

    And to answer your question about adding something to the Task Information window, sorry no can do. That is a view/popup internal to the application and are not user modifiable.

    Hope this helps.

    John


    • Edited by John - Project Thursday, July 11, 2019 3:38 PM answer question
    • Marked as answer by roryTriesVBA Friday, July 19, 2019 12:19 AM
    Thursday, July 11, 2019 3:04 PM
  • Thanks for the advice John.

    I followed your general approach with a small tweak. Luckily the SetTaskField method operates on Task objects that are selected in the Team Planner view when the parameter AllSelectedTasks is set to true. I use this method to assign an identity tag in one of the tasks custom fields while in the Team Planner and then have a loop that runs through all the projects tasks, finds this tag and extracts the task's ID from it. This task ID is then used to run the Split method. The VBA code is shown below:

    Sub CreateSplit()
        Dim WhichTask As Long
        Dim t As Task
        Dim ts As Tasks
        Dim commentName As Variant
        Dim taskID As Long
        Dim SplitFrom As Variant, SplitTo As Variant
        Dim splitDuration As Long
        Dim endDate As Variant
        
        Set ts = ActiveProject.Tasks

        SetTaskField Field:="Comments", Value:="selectedTask", AllSelectedTasks:=True
        
        For Each t In ts
            If Not t Is Nothing Then
                If Not t.Summary Then
                commentName = t.GetField(FieldNameToFieldConstant("Comments"))
                    If commentName = "selectedTask" Then
                    taskID = t.GetField(pjTaskID)
                    t.SetField Application.FieldNameToFieldConstant("Comments"), ""
                    End If
                End If
            End If
        Next t

        taskID = CInt(taskID)
        Set t = ActiveProject.Tasks(taskID)
        SplitFrom = InputBox("Enter the date and time for the start of the" & " split: " & vbCrLf & vbCrLf & "(The default time is the end" & " time of the preceding working period. 26/06/19)")
        SplitTo = InputBox("Enter the date and time for the end of the split:" & vbCrLf & vbCrLf & "(The default time is the start time of the next" & " working period. 26/06/19)")
        SplitFrom = SplitFrom & " 6:00 AM"
        SplitTo = SplitTo & " 6:00 AM"
        ActiveProject.Tasks(taskID).Split SplitFrom, SplitTo
        
        SplitFrom = DateValue(SplitFrom)
        SplitTo = DateValue(SplitTo)
        splitDuration = DateDiff("d", SplitFrom, SplitTo) * -1
        endDate = t.GetField(Application.FieldNameToFieldConstant("Finish"))
        endDate = Right(endDate, 8)
        endDate = DateValue(endDate)
        endDate = DateAdd("d", splitDuration, endDate)
        t.SetField Application.FieldNameToFieldConstant("Finish"), endDate
        
        
    End Sub



    Monday, July 15, 2019 1:42 AM
  • roryTriesVBA,

    You're welcome and thanks for the feedback. I'd probably simplify the macro a bit. For example, if your custom field is Text1, your loop could be,

    SetTaskField Field:="Text1", Value:="selectedTask", AllSelectedTasks:=True
        
        For Each t In ActiveProject.Tasks
            If Not t Is Nothing Then
                If Not t.Summary Then
                    If t.Text1 = "selectedTask" Then
                        taskID = t.ID
                        t.Text1 = ""
                        Exit For
                    End If
                End If
            End If
        Next t

    Also, your input boxes ask for a date and time but then the code "resets" the time to 6:00 AM, so why ask for the time.

    Nonetheless, if it's working for you, go with it and give yourself credit.

    John

    Monday, July 15, 2019 2:29 AM
  • Legend, thanks for the advice John! Will implement your suggestions to clean things up. 

    I append the time to the date variable as it removes the need for user to input them and shortens time - all tasks are set to start at the same time. But yes, the prompt needs to be edited.

    Cheers.

    Thursday, July 18, 2019 2:48 AM