How to determine task assignments in PSI ???

P

Paul

I am trying to create a datatable of task assignments in PSI. I am using C#,
Visual Studio 2008, and Microsoft Project Server 2007. The code sample I
have included below compiles perfectly and it seems to work until you go to
read the actual values in assignmentRow, and then you have problems. The
TASK_NAME and RES_NAME are both DBNull. Also If you try to open the
assignmentRow object in debug to see what is in there, you get Strong Type
Exception messages. Any ideas?

// Set up the Web service objects
ProjectWebSvc.Project projectSvc = new
ProjectWebSvc.Project();

projectSvc.Url = p_projectServerURI + p_projectServicePath;
projectSvc.Credentials = CredentialCache.DefaultCredentials;

ProjectWebSvc.ProjectDataSet projectDs =
projectSvc.ReadProjectEntities(projGUID, 2 | 4 | 8,
ProjectWebSvc.DataStoreEnum.WorkingStore);

ProjectWebSvc.ProjectDataSet.AssignmentDataTable
assignmentTable = projectDs.Assignment;

foreach (ProjectWebSvc.ProjectDataSet.AssignmentRow
assignmentRow in assignmentTable)
{
row = table.NewRow();
row["Act"] = assignmentRow.TASK_NAME;
row["Resource"] = assignmentRow.RES_NAME;
table.Rows.Add(row);
}

row and table are objects created earlier in the code, but they aren't the
problem. The problem is something to do with the way I am trying to read the
assignmentRow object.

Thanks!

Paul
 
S

Stephen Sanderlin [MVP]

You're seeing DBNull because (as far as I've seen) these columns are
always empty in the AssignmentDataTable. Since they are part of the
ProjectDataSet, I can only assume that they are populated in some
situation (perhaps an internal mechanism) that I have yet to observe.
However, they have always been DBNull for me.

Here's revised code that will work for you:

// Set up the Web service objects
ProjectWebSvc.Project projectSvc = new
ProjectWebSvc.Project();

projectSvc.Url = p_projectServerURI + p_projectServicePath;
projectSvc.Credentials = CredentialCache.DefaultCredentials;

ProjectWebSvc.ProjectDataSet projectDs =
projectSvc.ReadProjectEntities(projGUID, 2 | 4 | 8,
ProjectWebSvc.DataStoreEnum.WorkingStore);

ProjectWebSvc.ProjectDataSet.AssignmentDataTable
assignmentTable = projectDs.Assignment;

foreach (ProjectWebSvc.ProjectDataSet.AssignmentRow
assignmentRow in assignmentTable)
{
ProjectWebSvc.ProjectDataSet.TaskRow _taskRow =
projectDs.Task.FindByTASK_UIDPROJ_UID(
assignmentRow.TASK_UID, projGUID);
ProjectWebSvc.ProjectDataSet.ProjectResourceRow _resRow
=

projectDs.ProjectResource.FindByRES_UIDPROJ_UID(assignmentRow.RES_UID,
projGUID);

row = table.NewRow();
row["Act"] = _taskRow.TASK_NAME;
row["Resource"] = _resRow.RES_NAME;
//row["Act"] = assignmentRow.TASK_NAME;
//row["Resource"] = assignmentRow.RES_NAME;
table.Rows.Add(row);

There are other ways of doing this without using the FindBy...() methods
(e.g. LINQ) -- I chose this syntax because it accomplishes your goal
with a minimum of refactoring.

As a rule, you want to use the FK GUIDs in each ProjectDataSet table to
retrieve information about a foreign entity (e.g. use the TASK_UID to
retrieve the TASK_NAME from the TaskDataTable).

Hope that helps!
Steve

--
Stephen Sanderlin, Project MVP
VP of Technology
MSProjectExperts

For Project Server Consulting: http://www.msprojectexperts.com
For Project Server Training: http://www.projectservertraining.com

Read our blog at: http://www.projectserverhelp.com

Learn | Connect | Grow @ The Microsoft Project Conference
Phoenix, AZ - September 14-17, 2009



I am trying to create a datatable of task assignments in PSI. I am using C#,
Visual Studio 2008, and Microsoft Project Server 2007. The code sample I
have included below compiles perfectly and it seems to work until you go to
read the actual values in assignmentRow, and then you have problems. The
TASK_NAME and RES_NAME are both DBNull. Also If you try to open the
assignmentRow object in debug to see what is in there, you get Strong Type
Exception messages. Any ideas?

// Set up the Web service objects
ProjectWebSvc.Project projectSvc = new
ProjectWebSvc.Project();

projectSvc.Url = p_projectServerURI + p_projectServicePath;
projectSvc.Credentials = CredentialCache.DefaultCredentials;

ProjectWebSvc.ProjectDataSet projectDs =
projectSvc.ReadProjectEntities(projGUID, 2 | 4 | 8,
ProjectWebSvc.DataStoreEnum.WorkingStore);

ProjectWebSvc.ProjectDataSet.AssignmentDataTable
assignmentTable = projectDs.Assignment;

foreach (ProjectWebSvc.ProjectDataSet.AssignmentRow
assignmentRow in assignmentTable)
{
row = table.NewRow();
row["Act"] = assignmentRow.TASK_NAME;
row["Resource"] = assignmentRow.RES_NAME;
table.Rows.Add(row);
}

row and table are objects created earlier in the code, but they aren't the
problem. The problem is something to do with the way I am trying to read the
assignmentRow object.

Thanks!

Paul
 
P

Paul

This is almost exactly what I ended up doing. I tried to post this yesterday,
but the forum didn't accept my message for some reason. Thanks so much for
the help

Stephen Sanderlin said:
You're seeing DBNull because (as far as I've seen) these columns are
always empty in the AssignmentDataTable. Since they are part of the
ProjectDataSet, I can only assume that they are populated in some
situation (perhaps an internal mechanism) that I have yet to observe.
However, they have always been DBNull for me.

Here's revised code that will work for you:

// Set up the Web service objects
ProjectWebSvc.Project projectSvc = new
ProjectWebSvc.Project();

projectSvc.Url = p_projectServerURI + p_projectServicePath;
projectSvc.Credentials = CredentialCache.DefaultCredentials;

ProjectWebSvc.ProjectDataSet projectDs =
projectSvc.ReadProjectEntities(projGUID, 2 | 4 | 8,
ProjectWebSvc.DataStoreEnum.WorkingStore);

ProjectWebSvc.ProjectDataSet.AssignmentDataTable
assignmentTable = projectDs.Assignment;

foreach (ProjectWebSvc.ProjectDataSet.AssignmentRow
assignmentRow in assignmentTable)
{
ProjectWebSvc.ProjectDataSet.TaskRow _taskRow =
projectDs.Task.FindByTASK_UIDPROJ_UID(
assignmentRow.TASK_UID, projGUID);
ProjectWebSvc.ProjectDataSet.ProjectResourceRow _resRow
=

projectDs.ProjectResource.FindByRES_UIDPROJ_UID(assignmentRow.RES_UID,
projGUID);

row = table.NewRow();
row["Act"] = _taskRow.TASK_NAME;
row["Resource"] = _resRow.RES_NAME;
//row["Act"] = assignmentRow.TASK_NAME;
//row["Resource"] = assignmentRow.RES_NAME;
table.Rows.Add(row);

There are other ways of doing this without using the FindBy...() methods
(e.g. LINQ) -- I chose this syntax because it accomplishes your goal
with a minimum of refactoring.

As a rule, you want to use the FK GUIDs in each ProjectDataSet table to
retrieve information about a foreign entity (e.g. use the TASK_UID to
retrieve the TASK_NAME from the TaskDataTable).

Hope that helps!
Steve

--
Stephen Sanderlin, Project MVP
VP of Technology
MSProjectExperts

For Project Server Consulting: http://www.msprojectexperts.com
For Project Server Training: http://www.projectservertraining.com

Read our blog at: http://www.projectserverhelp.com

Learn | Connect | Grow @ The Microsoft Project Conference
Phoenix, AZ - September 14-17, 2009



I am trying to create a datatable of task assignments in PSI. I am using C#,
Visual Studio 2008, and Microsoft Project Server 2007. The code sample I
have included below compiles perfectly and it seems to work until you go to
read the actual values in assignmentRow, and then you have problems. The
TASK_NAME and RES_NAME are both DBNull. Also If you try to open the
assignmentRow object in debug to see what is in there, you get Strong Type
Exception messages. Any ideas?

// Set up the Web service objects
ProjectWebSvc.Project projectSvc = new
ProjectWebSvc.Project();

projectSvc.Url = p_projectServerURI + p_projectServicePath;
projectSvc.Credentials = CredentialCache.DefaultCredentials;

ProjectWebSvc.ProjectDataSet projectDs =
projectSvc.ReadProjectEntities(projGUID, 2 | 4 | 8,
ProjectWebSvc.DataStoreEnum.WorkingStore);

ProjectWebSvc.ProjectDataSet.AssignmentDataTable
assignmentTable = projectDs.Assignment;

foreach (ProjectWebSvc.ProjectDataSet.AssignmentRow
assignmentRow in assignmentTable)
{
row = table.NewRow();
row["Act"] = assignmentRow.TASK_NAME;
row["Resource"] = assignmentRow.RES_NAME;
table.Rows.Add(row);
}

row and table are objects created earlier in the code, but they aren't the
problem. The problem is something to do with the way I am trying to read the
assignmentRow object.

Thanks!

Paul
 
Top