You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过ProjectEntry图/C#代码创建项目时模板任务未加载的问题

问题描述

在Acumatica定制开发中,通过ProjectEntry图与PMProject DAC以C#代码创建项目后,发现模板关联的任务并未同步到新项目中。原代码如下:

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

PMProject 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();
解决方案

Acumatica中仅设置TemplateID并保存项目,不会自动触发模板任务的复制逻辑,需要主动调用项目图中的对应方法。具体操作如下:

  • 先插入并保存新项目,确保生成有效的ContractID
  • 调用ProjectEntry图的CopyTemplateTasks方法,传入新项目的ContractID,完成模板任务的复制
  • 再次执行持久化操作,将复制后的任务数据保存到数据库

修改后的完整代码示例:

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

PMProject 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";

//Insert and save the new project first to generate valid ContractID
pmproj = projentry.Project.Insert(pmproj);                                
projentry.Persist();

//Copy tasks from the specified template to the new project
projentry.CopyTemplateTasks(pmproj.ContractID);

//Persist the copied task data
projentry.Persist();
额外注意事项
  • 确认目标模板项目(00TEMPLATE01)本身包含可复制的有效任务,且模板状态允许被复用
  • 确保新项目处于可接受任务的状态(如Active),避免状态限制导致任务复制失败

内容的提问来源于stack exchange,提问作者pmfith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 15:27:11