none
Project Server: Create project with required custom fields using CSOM RRS feed

  • Question

  • Hello.

    We need to create projects for our Project Server programmatically. For this we use the CSOM API.

    For creating a new project we define the ProjectCreationInformation and add it to the ProjectContext.Projects like this:

    var context = new ProjectContext(ProjectServerUri);
    var projectCreationInformation = new ProjectCreationInformation
            {
                    Id = Guid.NewGuid(),
                    Name = "The project name",
                    Description = "The project description",
                    Start = DateTime.Now.Date,
                    EnterpriseProjectTypeId = GetProjectTypeId()
            };
    var publishedProject = context.Projects.Add(projectCreationInformation);
    var update = this.context.Projects.Update();
    context.WaitForQueue(update, 10);

    This works fine as long as there are no custom fields defined as required. But we do have custom fields defined as required and will get the following exception:

    "PJClientCallableException: CustomFieldRequiredValueNotProvided"

    We know which field causes the exception but we are not able to manage the necessary assignment. Neither assigning the value to the PublishedProject instance, nor the assignment to its draft (PublishedProject.Draft) seems to work:

    var context = new ProjectContext(ProjectServerUri);
    var projectCreationInformation = new ProjectCreationInformation
            {
                    Id = Guid.NewGuid(),
                    Name = "The project name",
                    Description = "The project description",
                    Start = DateTime.Now.Date,
                    EnterpriseProjectTypeId = GetProjectTypeId()
            };
    var publishedProject = context.Projects.Add(projectCreationInformation);

    //1. trying to assign the value to the PublishedProject instance
    publishedProject.SetCustomFieldValue(GetInternalName("RequiredField"), GetValue("RequiredField"));

    //2. trying to assign the value to the DraftProject instance
    var draftProject = publishedProject.Draft; //.IncludeCustomFields;
    draftProject.SetCustomFieldValue(GetInternalName("RequiredField"), GetValue("RequiredField"));

    var update = this.context.Projects.Update();
    context.WaitForQueue(update, 10);

    The internal name and the value (GetInternalName("RequiredField"), GetValue("RequiredField")) are both fine.

    Even after trying to load the custom fields (PublishedProject instance/DraftProject instance) and including the custom fields (.IncludeCustomFields property) in several combinations, none of our attempts was successful. Could you please tell us, how to create a project for Project Server programmatically and directly assign the required custom fields using the CSOM API?

    Best regards


    Monday, October 26, 2015 2:47 PM

All replies

  • I'm getting the same problem but i'm using Project Server 2016!

    Any idea?

    The same problem, other post: https://social.msdn.microsoft.com/Forums/en-US/06e15333-b59e-47a8-ab32-0c9437c15770/creating-a-project-with-required-custom-field-using-csom-customfieldrequiredvaluenotprovided?forum=project2010custprog

    Thursday, August 31, 2017 12:16 PM