Search code examples
acumatica

Why aren't the Template tasks coming in when I create a project using a graph extension / C# code?


I have a customization where I'm creating projects in code using the ProjectEntry graph and the PMProject DAC:

//create the project graph...
ProjectEntry projentry = PXGraph.CreateInstance<ProjectEntry>();

pmproj = new PMProject();

//Set the ProjectID:
pmproj.ContractCD = "000001"; //Project preferences is set to allow manually created project CDs...

//The template ID...
var tmplt = (PMProject)PXSelect<PMProject, 
                       Where<PMProject.contractCD, Equal<Required<PMProject.contractCD>>>>.Select(Base, "00TEMPLATE01");

pmproj.TemplateID = tmplt.ContractID;

//The description....
pmproj.Description = "Test description";

//Now save the new project...
pmproj = projentry.Project.Insert(pmproj);                                
projentry.Persist();

It's not picking up the template tasks. Is there something else I need to do to get those tasks to come into the project?


Solution

  • There is a separate method that you need to trigger to populate settings from a project template. DefaultFromTemplate(Project.Current, newTempleteID, DefaultFromTemplateSettings.Default);

    It is executed automatically when you do that from UI, but if you do that from cod you need to do it manually.