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

Viewed 30

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?

2 Answers

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.

Try this alternative approach to the sequence in which the values are entered in the Cache:

ProjectEntry projentry = PXGraph.CreateInstance<ProjectEntry>();    
pmproj = new PMProject();
pmproj.ContractCD = "000001";
pmproj = projentry.Project.Insert(pmproj); 

var tmplt = (PMProject)PXSelect<PMProject, 
                       Where<PMProject.contractCD, Equal<Required<PMProject.contractCD>>>>.Select(Base, "00TEMPLATE01");    
pmproj.TemplateID = tmplt.ContractID;
projentry.Project.Update(pmproj);                                        
pmproj.Description = "Test description";
projentry.Project.Update(pmproj);                                        
projentry.Actions.PressSave();
Related