How to copy a (split) task

M

Marcelo K

I have a resource r and want to copy its assignments to another project.
I tried to add a new assignment and then assigning the same start date and
work. But it doesn't quite work when it comes to copy an asiggnemnt that was
split.
What is the recommended way to copy assignments ? (BTW, what is the exact
relation between the porject tasks and the resources assignemenst?)
 
J

John

Marcelo K said:
I have a resource r and want to copy its assignments to another project.
I tried to add a new assignment and then assigning the same start date and
work. But it doesn't quite work when it comes to copy an asiggnemnt that was
split.
What is the recommended way to copy assignments ? (BTW, what is the exact
relation between the porject tasks and the resources assignemenst?)

Marcelo,
Even though you posted to a newsgroup that deals primarily with
developer questions/issues (e.g. VBA, PDS, etc.), I don't see any
mention of wanting to automate the process. I will therefore assume you
just want to do a manual operation.

First of all let me answer the second part of your post. Project tasks
are the activities to be performed by one or more resources as part of a
larger overall plan. They are described using action verbs since some
action must take place. Resources are the human or material entities
that actually cause the task to be completed. Assignments are the bridge
between the two. When looking at a task, a resource is "assigned" to the
task. When looking at a resource, a task is the assignment of that
resource. All three are objects in the Project database and each has
some unique and some shared characteristics. A task and a resource can
exist as independent objects but an assignment can only exist if both a
task and a resource are present (i.e. you can't have a "bridge" if there
is nothing to connect).

When you say you created a new assignment it isn't clear exactly what
you did. Since an assignment can only exist in the presence of both a
task and a resource, an assignment cannot be copied independently from
one file to another, unless the same task and resource already exist in
both files. I will assume the latter is not true and you simply want to
re-create the same task and resource with it's assignments in a second
file. Probably the easiest way to do that is to simply copy the task.
The resource assigned to that task will copy with it and if the task is
split, the split should also go with it. Even if the task and the
resource already exist in both files, it is still easier to do the full
task copy and then delete the redundant original task in the second file.

Hope this helps.
John
Project MVP
 
M

Marcelo K

John, I really must have been so not clear about my goal. This is actually a
follow up on a post I made some time ago. I replied there, but for some
reason the post did not come to the top of list, by date, therefore I though
nobody will really see I was following up, so I created this new post.

I tried to achieve copying a task with the code below. It works well for
assignments that are not splitted.
Your explanation was informative, but I did not manage to understand how the
split information is stored, and how am I supposed to recreate it if I want
to "copy" that splitted task.
Since all I've got is the resource, I don't know how to get to the original
task. You said the assignments are the bridge between the resource and the
task; so how do I address the task, having the resource, and the "bridge"?


Private Sub CreateResGroup(r As Resource)
Dim header as Long
Dim asg As Assignment

'Add a summary task with the name of the resource
header = ActiveProject.Tasks.Add(r.Name)
ActiveProject.Tasks(header).SetField pjTaskOutlineLevel, "1"

'Copy the resource assignments, make it "subtask"
For Each asg In r.Assignments
newasg = ActiveProject.Tasks.Add(asg.TaskName)
With ActiveProject.Tasks(newasg)
.Start = asg.Start
.Finish = asg.Finish
.Work = asg.Work
.Estimated = "No"
.Milestone = "No"
.SetField pjTaskOutlineLevel, "2"
.SetField pjTaskRollup, "Yes"
End With
Next asg
End Sub


In case you want to look at the full history, this would be the link to the
original post "Task Serial View" on this forum:
http://www.microsoft.com/office/com...d645&catlist=&dglist=&ptlist=&exp=&sloc=en-us
 
J

John

Marcelo K said:
John, I really must have been so not clear about my goal. This is actually a
follow up on a post I made some time ago. I replied there, but for some
reason the post did not come to the top of list, by date, therefore I though
nobody will really see I was following up, so I created this new post.

I tried to achieve copying a task with the code below. It works well for
assignments that are not splitted.
Your explanation was informative, but I did not manage to understand how the
split information is stored, and how am I supposed to recreate it if I want
to "copy" that splitted task.
Since all I've got is the resource, I don't know how to get to the original
task. You said the assignments are the bridge between the resource and the
task; so how do I address the task, having the resource, and the "bridge"?


Private Sub CreateResGroup(r As Resource)
Dim header as Long
Dim asg As Assignment

'Add a summary task with the name of the resource
header = ActiveProject.Tasks.Add(r.Name)
ActiveProject.Tasks(header).SetField pjTaskOutlineLevel, "1"

'Copy the resource assignments, make it "subtask"
For Each asg In r.Assignments
newasg = ActiveProject.Tasks.Add(asg.TaskName)
With ActiveProject.Tasks(newasg)
.Start = asg.Start
.Finish = asg.Finish
.Work = asg.Work
.Estimated = "No"
.Milestone = "No"
.SetField pjTaskOutlineLevel, "2"
.SetField pjTaskRollup, "Yes"
End With
Next asg
End Sub


In case you want to look at the full history, this would be the link to the
original post "Task Serial View" on this forum:
http://www.microsoft.com/office/community/en-us/default.mspx?query=Serial&dg=m
icrosoft.public.project.developer&cat=en-us-microsoftproject&lang=en&cr=US&pt=
a1d023a3-f612-4da2-acb8-fda8f850d645&catlist=&dglist=&ptlist=&exp=&sloc=en-us

Marcelo,
Unfortunately I don't have time to check the past thread, or to critique
your code, at the moment. However until I find some time to give you a
more complete response, you might want to take a look at the SplitParts
Object and the SplitParts Collection Object. Those can be used to find
and re-assign split task information from one file to another.

Hopefully this will give you a head start.

John
Project MVP
 
J

John

Marcelo K said:
John, I really must have been so not clear about my goal. This is actually a
follow up on a post I made some time ago. I replied there, but for some
reason the post did not come to the top of list, by date, therefore I though
nobody will really see I was following up, so I created this new post.

I tried to achieve copying a task with the code below. It works well for
assignments that are not splitted.
Your explanation was informative, but I did not manage to understand how the
split information is stored, and how am I supposed to recreate it if I want
to "copy" that splitted task.
Since all I've got is the resource, I don't know how to get to the original
task. You said the assignments are the bridge between the resource and the
task; so how do I address the task, having the resource, and the "bridge"?


Private Sub CreateResGroup(r As Resource)
Dim header as Long
Dim asg As Assignment

'Add a summary task with the name of the resource
header = ActiveProject.Tasks.Add(r.Name)
ActiveProject.Tasks(header).SetField pjTaskOutlineLevel, "1"

'Copy the resource assignments, make it "subtask"
For Each asg In r.Assignments
newasg = ActiveProject.Tasks.Add(asg.TaskName)
With ActiveProject.Tasks(newasg)
.Start = asg.Start
.Finish = asg.Finish
.Work = asg.Work
.Estimated = "No"
.Milestone = "No"
.SetField pjTaskOutlineLevel, "2"
.SetField pjTaskRollup, "Yes"
End With
Next asg
End Sub


In case you want to look at the full history, this would be the link to the
original post "Task Serial View" on this
forum:http://www.microsoft.com/office/community/en-us/default.mspx?query=Seria
l&dg=microsoft.public.project.developer&cat=en-us-microsoftproject&lang=en&cr=
US&pt=a1d023a3-f612-4da2-acb8-fda8f850d645&catlist=&dglist=&ptlist=&exp=&sloc=
en-us

Marcelo,
I found some time to look at the previous thread and now I understand
why you are creating a summary "task" with the resource name (it made no
sense to me from your post). My earlier response suggesting the
SplitParts collection should get the information you need although I'm
not sure how readable it will be when rolled up.

With regard to a previous question you had about wrapping the text in
the bar. Sorry, Project isn't that sophisticated. Putting any text
inside a Gantt bar pretty much requires that a heavy amount of
abbreviating be used. Personally, I never put text in a bar - it is just
to cluttered.

If the SplitParts suggestion doesn't do what you need, let us know.

John
Project MVP
 
M

Marcelo K

Thank you John,

I started to play a little bit with the SplitParts collection. In order
to do that I made two changes to my code:
1. I pass the original Tasks collection as parameter (named ts), so I can
find there the split parts and
2. Added a loop to the copying part:

For Each sp In ts(asg.TaskID).SplitParts
.Split sp.Start, sp.Finish
' tried also .SplitParts.Add sp.Start, sp.Finish
Next sp

And, even though I can see, through the watch window, the splitparts were
copied, I don't see the split in the gantt view.

For example, given the original task is a 2d task, splited into 1d on
07-Feb-06 and another 1d on 18-Feb-06.
When I copy it (by the code I poseted before) I create a new task, copy
the start date (07-Feb-06), copy the end date (18-Feb-06) and the work (960
minutes) and then copy the splitparts.
What I see in the Gantt is a single task (no visible split) with 12d
duration (7-Feb to 18-Feb).
I tried not to copy the finish date, but it did no good.

My strongest suspicion is that this is not the right way to copy a task
by program. Unfortunately it seems to be that nobody ever needed to do such a
copy, because I cannot find anywhere a pointer to some sample code for this,
not in these forums, even not google can find some useful link about it.
 
J

John

Marcelo K said:
Thank you John,

I started to play a little bit with the SplitParts collection. In order
to do that I made two changes to my code:
1. I pass the original Tasks collection as parameter (named ts), so I can
find there the split parts and
2. Added a loop to the copying part:

For Each sp In ts(asg.TaskID).SplitParts
.Split sp.Start, sp.Finish
' tried also .SplitParts.Add sp.Start, sp.Finish
Next sp

And, even though I can see, through the watch window, the splitparts were
copied, I don't see the split in the gantt view.

For example, given the original task is a 2d task, splited into 1d on
07-Feb-06 and another 1d on 18-Feb-06.
When I copy it (by the code I poseted before) I create a new task, copy
the start date (07-Feb-06), copy the end date (18-Feb-06) and the work (960
minutes) and then copy the splitparts.
What I see in the Gantt is a single task (no visible split) with 12d
duration (7-Feb to 18-Feb).
I tried not to copy the finish date, but it did no good.

My strongest suspicion is that this is not the right way to copy a task
by program. Unfortunately it seems to be that nobody ever needed to do such a
copy, because I cannot find anywhere a pointer to some sample code for this,
not in these forums, even not google can find some useful link about it.

Marcelo,
If the split parts are indeed copied, which seems to be the case by what
you see in the watch window, then it may just be a simple matter of
making sure there is a Gantt bar format for showing the split. Go to
Format/Bar Styles for the new project file and see if there is a "bar"
for showing splits. If not create one. If there is, try creating a
little test loop that looks at all tasks in the new file and examines
the Count property of the SplitParts object. Note that any normal task
has at least one split part so look for tasks with a count of > 1. If
nothing shows up then you are probably not correctly interpreting what
the watch window is telling you and you will need to examine your code
more closely to find out why it isn't working.

As far as a right or wrong way to do something, it is more a matter of
effectiveness. In other words, does the approach you are using work? If
it does, then it is a "right" way - it may not be the most efficient way
but it certainly is "right" because it does work.

You are correct about not being able to find much information on what
you are doing. Very few, if any, users want or need to copy individual
tasks (including splits) from one file to another in the manner you
want. You have a unique need so you have to develop your own process.

John
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top