ProjectAssignmentNew problems

V

Voonte

Hello,

I'm looking for a way to make some modifications to an Assignment when a new
is created. The ProjectAssignmentNew event seemed to be the one I needed but
I can't figure out how to get the Assignment object from the provided ID
parameter. I looped through the available Assignments in task ActiveCell.Task
(is there a better way to get the Task based on the Assignment ID?) but the
assignment wasn't registered with the Task. Is there a way to modify an
Assignment after it was created?

Appreciating any help.
 
G

Gary Phillips, PMP, SM&A Consulting

Hello Voonte

I also posted this answer under Microsoft.public.project.general.

I have spent hours (days over the course of 1 1/2 years) trying to find a
way around the very problem you describe, but like you, found no way to
directly populate the fields of a new assignment using ProjectAssignmentNew ,
since the assignment appears to be associated with the Task or Resource AFTER
the ProjectAssignmentNew event takes place.

I am assuming here that you are adding tasks manually.

Tonight, I finally arrived at a way to achieve what we both need. MS
Project triggers two events when a new assignment is added. The first event
is the ProjectAssignmentNew event. The second event is the
WindowSelectionChange event.

The typical scenario when manually adding assignments is that you add the
resources to the task and then press enter. Normally this action places the
focus on the next row below, or the field next to the Resource Names field.
Either way, I found that the WindowSelectionChange event triggers after the
ProjectAssignmentNew event. By this time, the new assignment IS associated
with the Task, but also by this time, the focus is now sitting on a different
Task, so you lose the ability to use Activecell.task.uniqueId to locate the
correct assignment.

What you have to do is use the ProjectAssignmentNew event to record
information about the Task to which you added the resource(s), and use the
WindowChangeSelection event to modify the assignment(s) you just added. I
set up a fast test case to see if this would actually work, and it does. You
could use static public variables, etc. to record and retain information
about the task until the WindowSelectionChange event triggers. Since I
prefer not to use public variables, I have extensive functions and procedures
set up to access the CustomDocumentProperties, so for convenience I stored
the Unique ID of the task to which I added the resource in a Custom Document
Property. I then retrieved the Unique ID during the WindowSelectionChange
event and used that to access the newly added assignment.

"Activeproject.tasks.uniqueid (Uniqued ID I retrieved from the custom doc.
properties).assignments.count" gave me the index of the last assignment.
From there, I was easily able to access all of the properties of the newly
added assignment.

During the WindowSelectionChange event I reset the value stored in the
Custom Document Property to "None" so that I would know to blow past the new
assignment procedure embedded in the WindowChangeSelection event, which
triggers often for other reasons.

I haven't tried this yet on multiple resources added at the same time, but
feel enough information is available during both events to update all of the
newly added assignments.

Hope this solves your problem. It solved mine.

Gary Phillips, PMP, Sr. Plannning & MS Project Consultant, SM&A
 

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