none
Selecting Project Object of Task RRS feed

  • Question

  • As the title indicates, is it possible to get the Project object of a Task?

    I know I can get the name of it using Task.Project, then search for it to get the Project object, but I'm using sub-sub-projects, which could result in the project name being found in multiple parent projects. So, I need to be able to distinguish one from the other, to locate it despite the multiple instances of the same name.

    Friday, June 1, 2018 12:57 PM

Answers

  • Hi Angel,

    I think you've caught me mis-remembering what I used to find in the Project (vs. the Parent) field.

    Regarding the data to compare, I've found task.GUID to be a reliable comparison key for linked subproject tasks, though I haven't used it in all cases for one reason or another (probably ignorance.)

    Yep, ID's are dynamic in that inserting a task into the current table typically increments the ID's of all those tasks below the insertion point.  UniqueID is indeed unique - but only within a single project file.  When you link subprojects into a master project, the task IDs from the subprojects are preserved - and thereby duplicated.  As a result the combined project ends up with multiple tasks with ID=1, etc.  Project transforms the UniqueIDs of the subproject tasks when included in the master - this preserves their uniqueness but makes them useless for the purpose discussed here.

        

    Friday, June 1, 2018 8:01 PM

All replies

  • Angel,

    As usual I'm confused. You talk about a project name being found in multiple parent projects in a multi-level consolidated project however Project only allows one instance of a given project to be inserted so how do you have the same name being found at multiple levels?

    What exactly are you trying to do? An example would help.

    John

    Friday, June 1, 2018 2:38 PM
  • My apologies for the confusion, I really don't mean to be confusing. Here's a screenshot of how it's possible: http://i.imgur.com/vHuP0G0.jpg

    What I'm trying to do is to use the ActiveSelection to identify a project selected for modification and preload the project details into the form I made. I can populate the information, but identifying the project is the issue.

    Because it's setup to consolidate across years, a project may be redeveloped in a later year, resulting in two projects with the same title information, but they'll be under different year-based subprojects. Identifying the project file to extract the information is easy when the project is selected, but if a task of the project is selected I can only get the name of the project. If I can get the actual Project object, I wouldn't have to bother with anything fancy to pick out the appropriate year, I could just extract it from the Path.

    Friday, June 1, 2018 3:03 PM
  • Angel,

    " ...is it possible to get the Project object of a Task?"

    This is a good question, and I'm also interested in answers from others.  In my experience, tasks that are members of sub-projects (or sub-sub-projects) of the current ActiveProject have [Parent] and [Project] members that are unpredictable.  Occasionally they resolve to Project.type objects (with good FullName properties), but mostly they just resolve to dead-end strings rather than objects.  I've typically had to use a brute-force approach to actually find and examine the source project.  (E.g. recursively search through the tasks of the subproject tree - via  CurrentProject.Subprojects(i).SourceProject.Tasks - until I find a task whose key data match the one selected.)  Better approaches would be welcome.  

    Good luck, tom


    Friday, June 1, 2018 4:14 PM
  • Tom BoyleBPC,

    I'm not really sure what the Project property is supposed to return, but the documentation says, "Gets the name of the project containing the Task. Read-only String." Assuming I read that correctly, just getting the project name back, not the Project object, is exactly what is expected.

    As for your process, are you saying you would compare the ActiveSelection task to all tasks of the ActiveProject.Subprojects(i).SourceProject.Tasks(j) until you found a match, correct? If so, what value of the task would I be comparing? The Guid, ID, or UniqueID? I would assume not the ID, since that is a dynamic value, but I don't know what the difference would be between the Guid and the UniqueID and whether I would be able to reliably use either one.

    From my work with databases, I would think that IDs wouldn't change, but there it goes and flatout says the IDs change when tasks are moved about. I'm not sure what I know anymore. ^^'

    Friday, June 1, 2018 5:39 PM
  • Hi Angel,

    I think you've caught me mis-remembering what I used to find in the Project (vs. the Parent) field.

    Regarding the data to compare, I've found task.GUID to be a reliable comparison key for linked subproject tasks, though I haven't used it in all cases for one reason or another (probably ignorance.)

    Yep, ID's are dynamic in that inserting a task into the current table typically increments the ID's of all those tasks below the insertion point.  UniqueID is indeed unique - but only within a single project file.  When you link subprojects into a master project, the task IDs from the subprojects are preserved - and thereby duplicated.  As a result the combined project ends up with multiple tasks with ID=1, etc.  Project transforms the UniqueIDs of the subproject tasks when included in the master - this preserves their uniqueness but makes them useless for the purpose discussed here.

        

    Friday, June 1, 2018 8:01 PM