none
How to create new project with custom fields using CSOM in Project Server 2013/20216 ?

    Pertanyaan

  • Hi Team,

    We used PSI to create new projects with custom fields. But now we are using CSOM and wanted to know how to set custom field values using CSOM while creating new project.

    Appreciates your quick response! 

    Thanks,

    Senin, 24 Juli 2017 06.42

Semua Balasan

  • Thanks Paul for reply. But we are using In-premise Project Server. Please suggest for it. 
    Senin, 24 Juli 2017 08.41
  • It will be the same approach using CSOM - just references different CSOM dlls.

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Senin, 24 Juli 2017 08.42
    Moderator
  • Hi Paul,

    The "ProjectCreateInformation" class don't have custom filed properties and we have some required custom fileds which needs to create new project.

    Appreciate your help.

    Thanks 

    Jumat, 28 Juli 2017 07.06
  • HI

    ProjectCreateInformation class makes a new published project. you can add a enterprise template name as wel (with enterprise fields), all will be copied to the new project. Then you have to check this project out into a draftproject object. 

    public csom.PublishedProject CreateProject(string projectName, DateTime startDate , string projectDescription="",string templateName = "")
            {
                csom.PublishedProject project=null;
                csom.ProjectCreationInformation newProj = new csom.ProjectCreationInformation();
    
                if (templateName != "")
                {
                    Context.Load(Context.EnterpriseProjectTypes);
                    Context.ExecuteQuery();
                    csom.EnterpriseProjectType newEpt = Context.EnterpriseProjectTypes.FirstOrDefault(p => p.Name == templateName);
                    if (newEpt != null)
                    {// Create a project from template
                        newProj.Name = RemoveForbiddenCharacters(projectName);
                        newProj.Start = startDate;
                        newProj.EnterpriseProjectTypeId = newEpt.Id;
                        project = Context.Projects.Add(newProj);
                    }
                    else throw new Exception($"EnterpriseProjectType with templatename {templateName} doesn't exist");
                }   else // template is empty
                {
                    // Create a project 
                    project = Context.Projects.Add(new csom.ProjectCreationInformation()
                    {
                        Name = projectName,
                        Start = startDate,
                        Description = projectDescription
                    });
                }
            
               csom.JobState jobState = Context.WaitForQueue(Context.Projects.Update(), 1000);      
               return project;
            }

    Then in the main program call

    // check out the proejct
                var project = S.CreateProject(Name, Start, Description, "GV Sjabloon 2017");
    
                var draft = project.CheckOut();
                // load context data we will use
                context.Load(context.CustomFields);
                context.Load(context.LookupTables, lt => lt.Include(a => a.Entries,a => a.Name));

    <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Helvetica; background-color: #000000} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Helvetica; background-color: #000000; min-height: 11.0px} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Helvetica; color: #008f00; background-color: #000000} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Helvetica; color: #b4261a; background-color: #000000} span.s1 {color: #0433ff} span.s2 {color: #b4261a} span.s3 {color: #000000} </style>

    From Project Techcenter

    Selasa, 31 Juli 2018 07.55