Setting the Project Owner
We are currently in the early stages of planning the next version of Project. To help plan out the work, we are using Project 2007. To begin, we needed to create a number of projects in bulk and decided to use the PSI to help out with the process. We already had the name for all the projects and the PMs who would be the owners. So, I created an application that read from a text file and set the PM as the project owner and some custom fields to be able to identify the projects.
It was important to set the project owner so that PM can easily access and manipulate the project plan created by the application. This is a fairly easy task when working with the project dataset. To set the project owner, set ProjectOwnerID to the GUID of the resource. The following method may help to look up the resource GUID:
private Guid GetResourceGuid(string ls_name)
{
WSResource.Resource lo_resWS =
(WSResource.Resource)mo_conn.GetWebService(Connection.Resource);
WSResource.ResourceDataSet lo_resDS = new WSResource.ResourceDataSet();
string nameColumn = lo_resDS.Resources.RES_NAMEColumn.ColumnName;
string resUID = lo_resDS.Resources.RES_UIDColumn.ColumnName;
PSLibrary.Filter.FieldOperationType equal =
PSLibrary.Filter.FieldOperationType.Equal;
PSLibrary.Filter lo_filter = new PSLibrary.Filter();
lo_filter.FilterTableName = lo_resDS.Resources.TableName;
lo_filter.Fields.Add(new PSLibrary.Filter.Field(resUID));
lo_filter.Criteria = new PSLibrary.Filter.FieldOperator(equal, nameColumn, ls_name);
lo_resDS = lo_resWS.ReadResources(lo_filter.GetXml(), false);
return (Guid)lo_resDS.Tables[lo_resDS.Resources.TableName].Rows[0][0];
}
Acourse, I knew all the PMs were resources on the Project Server instance and did not trap for errors for trying to access the dataset if no rows existed. If you use this method in general, you should put a try catch around:
(Guid)lo_resDS.Tables[lo_resDS.Resources.TableName].Rows[0][0];
This method also uses the connection object that I described in an early post for connecting to the PSI.
Chris Boyd
Comments
Anonymous
May 20, 2007
A more interesting question would be: how to change the project owner of an existing project? LastError=GeneralOnlyUpdatesAllowed ... MaxAnonymous
September 05, 2007
Hi Chris, My company is currently working on integrating PS 2007 into its core IT systems, automatically generating new projects based on feeds from another system. Currently, we have an issue in that we can't assign a Project Owner who isn't an Administrator. Is there a solution/workaround to this? Cheers, BenAnonymous
May 08, 2008
@max: try using the queueUpdate methods or queueaddto... methods. @ben: we got the same problem that is, after creating a project from template the project-owner is the template-author, so, for example a "projectmanager", who only have rights to open and save is own projects, can't change the project_owner ... greatings TimoAnonymous
September 23, 2008
Hi, Its a great info to start with. Being a novice in this field, would request if you could provide the complete listing of code. One question (forgive me if not relevant to the forum) How to programatically add local resources to enterprise resources. Thanks. Jabez