我想使用C#中的CSOM创建一个新项目(内部为Projectserver 2013)。 我可以创建新项目。如果要在企业自定义字段中填写值,则必须再次从服务器加载已保存的项目,并在自定义字段中填写。 (请参见源代码)。 但是对于我的要求,新项目将需要自定义字段。有没有一种方法可以发送请求中创建项目的自定义字段的值?
var projectCreationInformation = new ProjectCreationInformation();
projectCreationInformation.Id = Guid.NewGuid();
projectCreationInformation.Name = projectData.ProjectTitle;
projectCreationInformation.Description = "";
projectCreationInformation.EnterpriseProjectTypeId = GetEptUid("test_Csom");
projectCreationInformation.Start = DateTime.Today.Date;
PublishedProject newPublishedProj = ProjectContext.Projects.Add(projectCreationInformation);
QueueJob qJob = ProjectContext.Projects.Update();
JobState jobState = ProjectContext.WaitForQueue(qJob, 180);
if (jobState == JobState.Success)
{
ProjectContext.Load(ProjectContext.Projects, c => c.IncludeWithDefaultProperties(pr => pr.CustomFields));
ProjectContext.ExecuteQuery();
var projects = ProjectContext.LoadQuery(ProjectContext.Projects.Where(p => p.Id == projectCreationInformation.Id));
ProjectContext.Load(ProjectContext.CustomFields);
ProjectContext.ExecuteQuery();
DraftProject draftProject = projects.First().Draft;
JobState job1 = ProjectContext.WaitForQueue(draftProject.CheckIn(true), 30);
DraftProject projectCheckout = projects.First().CheckOut();
CustomField projCF = ProjectContext.CustomFields.FirstOrDefault(cf => cf.Name == "Test_ECF");
projectCheckout.SetCustomFieldValue(projCF.InternalName, "Test");
projectCheckout.Update();
ProjectContext.Load(projectCheckout);
projectCheckout.Publish(true);
ProjectContext.ExecuteQuery();
ProjectContext.Projects.Update();
ProjectContext.ExecuteQuery();
}