Condividi tramite


Create New Project From Template (2007)

Finally code samples for Project Server 2007 J.

When you are integrating an application to Project Server its common to create new projects on Project Server. These projects correspond to some process in your application. This could be from provisioning a new network tap to constructing a building. There are always certain commonalities within the project. To take advantage of this you want to create your new project based on a template.

The following procedure is where we start

        private Guid CallCreateProject(string projectName)

        {

            Guid templateUid = GetProjectTemplateGUID("InstallNetworkTap”);

            Guid newProject = myProject.CreateProjectFromTemplate(templateUid, projectName);

            // Change some data in the new project

            ProjectWS.ProjectDataSet templateProject;

            templateProject = myProject.ReadProject(newProject);

            string startDate = DateTime.Now.ToString("yyyyMMdd");

            ProjectDataSet.ProjectRow projectRow = (ProjectDataSet.ProjectRow)templateProject.Project.Rows[0];

            projectRow.PROJ_INFO_START_DATE = DateTime.Now;

            templateProject.Project.AcceptChanges();

            Guid jobGuid = Guid.NewGuid();

            Guid sessionGuid = Guid.NewGuid();

            myProject.QueueUpdateProject(jobGuid, sessionGuid, templateProject, false);

            return newProject;

        }

I left the extra code in there to change the start date as some more code for the reader to play with. When using the PDS in Project Server 2003 you provided the template name and new project name. With PSI in Project Server 2007 its similar, with the big difference being GUIDs. All entities within Project Server are uniquely identified by GUID, which also includes the template. So this brings us to the hole in the code above GetProjectTemplateGUID. That is actually a call I made up, with the code for it below.

        private Guid GetProjectTemplateGUID(string templateName)

        {

            Guid tempateGuid = Guid.NewGuid();

            ProjectWS.ProjectDataSet myProjectList = myProject.ReadProjectList();

            foreach (DataRow row in myProjectList.Project)

            {

                if ((string)row["PROJ_NAME"] == templateName)

                {

                    tempateGuid = (Guid)row["PROJ_UID"];

                }

            }

            return tempateGuid;

        }

Comments

  • Anonymous
    August 02, 2006
    Do you maybe know how to create/save a project workspace? I know how to create the project and how to publish that. I only need to save its workspace... PLZ answer to stro.na@interia.pl

  • Anonymous
    January 03, 2007
    ReadProject will never take one argument.And when i am trying to update the start date it is not getting updated.This is the code what i tried /Creating a Dataset to access list of projects in PS/            websvcprj.ProjectDataSet projectList = project.ReadProjectList();            /Getting Project UID of a particular project/            foreach (DataRow projectRow in projectList.Project)            {                if ((String)projectRow[projectList.Project.PROJ_NAMEColumn] == "Medium")                {                    projectUid = (Guid)projectRow[projectList.Project.PROJ_UIDColumn];                    break;                }            }            /Create Project using a Template/            Guid newProjectGuid = project.CreateProjectFromTemplate(projectUid, projectName);   System.Threading.Thread.Sleep(3000);            Guid jobGuid = Guid.NewGuid();            Guid sessionGuid = Guid.NewGuid();            /Checking out a created Project/            project.CheckOutProject(newProjectGuid, sessionGuid, "");            websvcprj.ProjectDataSet templateProject;            /Reading a project from a workingstore(drafts db)/            templateProject = project.ReadProject(newProjectGuid, websvcprj.DataStoreEnum.WorkingStore);            websvcprj.ProjectDataSet.ProjectRow projectRow1 = (websvcprj.ProjectDataSet.ProjectRow)templateProject.Project.Rows[0];            projectRow1.PROJ_INFO_START_DATE = DateTime.Parse("01/01/2007");            templateProject.Project.AcceptChanges();            //Updating the project            project.QueueUpdateProject(jobGuid, sessionGuid, templateProject, false);            Guid jobGuid2 = Guid.NewGuid();            //creating a dataset//-            websvcprj.ProjectRelationsDataSet dsProjectRelations = new websvcprj.ProjectRelationsDataSet();            Guid jobGuid3 = Guid.NewGuid();            string wssUrl = "";            bool fullPublish = true;            //Publishing the project            dsProjectRelations = project.QueuePublish(jobGuid3,                newProjectGuid, fullPublish, wssUrl);            //Checking in the project            project.QueueCheckInProject(jobGuid2, newProjectGuid, false, sessionGuid, "");            MessageBox.Show("Project created!");

  • Anonymous
    April 29, 2007
    Ram, Did you manage to solve this date problem? Because in my case also PROJ_INFO_START_DATE is not getting updated. Please get back to me. Thanks.

  • Anonymous
    June 01, 2007
    I tried the update the project using the method shown above. Code compiles and runs succesfully, but the project start date does not get updated? Ram - Did you find any alternative way to update the project start date?

  • Anonymous
    June 01, 2007
    I tried the update the project using the method shown above. Code compiles and runs succesfully, but the project start date does not get updated? Ram - Did you find any alternative way to update the project start date?

  • Anonymous
    June 15, 2007
    Thank you for you help. I am receiving a following error "GeneralQueueInvalidJobUID" on the Checkin Project call:   QueueCheckInProject(jobGuid2, newProjectGuid, false, sessionGuid, ""); Any Suggestions? Regards, Kishore

  • Anonymous
    July 09, 2007
    Ram, Sorry for delay in reply. But I am still not able to find out the way to set the start date and project owner after creation of the project from template. Code executes fine without error, but when you see the final result, it was not what you are expecting. It sets Project owner as template author. If you have some thoughts please let me know. Thanks.

  • Anonymous
    September 05, 2007
    Hi,  I tried creating project using the psi method CreateProjectFromTemplate and am getting the following errors:

  1. AssignmentCannotEditSummaryTask
  2. AssignmentNotFound If the template does not have any assignments I get the "AssignmentNotFound error" and if there are few assignments (not all tasks have resources) I get the "AssignmentCannotEditSummaryTask" error. Please can you let me know how to resolve this. What kind of templates are to be used for this method?
  • Anonymous
    November 12, 2007
    I cannot manage to update the start date for the project once it has already defined. It seems that the changes to PROJ_INFO_START_DATE field are just discarded (thought it is a readable/writable property). The changes are queued and executed without any exception being thrown but the start date keeps the original value and not the date set by code. Any ideas? Thanks.

  • Anonymous
    November 13, 2007
    Don't call AcceptChanges on the project row before calling UpdateProject... That should do it.

  • Anonymous
    January 29, 2008
    @Akila: Have you bound a lookup table to the custom field "Team Name"? If so, this is a known bug, MS is working on a hotfix. Workaround: delete all entries in this lut and create new templates. @All: Any news about setting the project start date? greating timo