Find new parent for indented/outdented task

B

billmiami2

When a user indents/outdents a task, I would like to trap the event,
find the task's new parent and assign some of the values from the new
parent to the task.

This would be very easy if I had an app_ProjectAfterTaskChange event,
but I don't (why not?). Nevertheless, I'm using the
app_ProjectBeforeTaskChange event and catching the indent/outdent by
testing if Field=pjTaskOutlineLevel. At this point, the task's parent
task is still the old parent task. However, NewVal is the new
OutlineLevel. Unfortunately, given the task's new outline level, I
don't know a foolproof way of finding the task's new parent.
Currently, I'm looping through all tasks and searching for the task
with an outline level of NewVal-1 and a task ID as close to but not
greater than the task's ID. I don't think this will give me a correct
answer in all cases.

I've also tried testing for Field=pjTaskParentTask, but this didn't
work.

Does anyone know a better way for me to do this?

Thanks,

Bill
 
J

JackD

For outdenting, the solution is simple.
The task's new outline parent is the task's former outline grandparent.
This:
task.outlineparent.outlineparent.name
returns the name of the new outline level.
Get all the information about the grandparent before the change and it will
hold true after the change.

For indenting, it will require working with ID's.
 
B

billmiami2

Jack,
parent is the task's former outline grandparent.<<

Excellent observation. I hadn't thought much about outdenting--I was
more focused on indenting.

A bit more testing revealed that my little function for finding the new
parent worked reliably for both indenting and outdenting. I didn't
think this would be the case because I thought that if tasks were
dragged and dropped into place, their IDs would no longer be
sequential. However, it seems that task IDs are renumbered after
drag/drop so that they do indeed remain sequential.

Bill
 

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