Acumatica如何以编程方式创建项目活动?

时间:2017-07-29 00:56:19

标签: acumatica

我正在尝试在创建项目后创建一个Activity,我收到以下错误

未找到项目ProjectTaskID(限制:False,外部:True,值:管理)
找不到项目ContractID(限制:False,外部:False,值:2285)

项目创建后RowUpdating中的代码位置。

                   var projTask = (PMTask)PXSelect<PMTask,
                   Where<PMTask.taskCD, Equal<Required<PMTask.taskCD>>,
                And<PMTask.projectID, Equal<Required<PMTask.projectID>>>>>
                    .SelectSingleBound(Base, new object[] { }, "Management", Base.Project.Current.ContractID);
                int projTID = projTask.TaskID.Value;
                        CRActivityMaint ent1 = PXGraph.CreateInstance<CRActivityMaint>();
                        CRActivity fold1 = new CRActivity();
                        fold1 = ent1.Activities.Insert(fold1);
                        fold1.Subject = "Drawings";
                        fold1.Type = "FC";

                        fold1.ContactID = Base.Project.Current.ContractID;
                        ent1.Activities.Update(fold1);
                        PMTimeActivity t1 = new PMTimeActivity();
                        t1.ContractID = Base.Project.Current.ContractID;
                        t1.Summary = "Drawings";

                        t1.TrackTime = true;
                        t1.ProjectID = Base.Project.Current.ContractID;
                        t1.ProjectTaskID = projTID;


                        ent1.TimeActivitiesOld.Insert(t1);
                        ent1.TimeActivity.Current = t1;

                        ent1.Actions.PressSave();

1 个答案:

答案 0 :(得分:0)

问题是因为TimeActivity未正确初始化

                        CRActivityMaint ent1 = PXGraph.CreateInstance<CRActivityMaint>();
                        CRActivity fold1 = new CRActivity();
                        fold1 = ent1.Activities.Insert(fold1);
                        fold1.Subject = "Drawings";
                        fold1.Type = "FC";
                        fold1.OwnerID = Base.Project.Current.CreatedByID; //change to proj manager item.UsrProjectMan get guid
                        ent1.Activities.Update(fold1);
                        ent1.TimeActivity.Current.Summary = "Drawnings";
                        ent1.TimeActivity.Current.TrackTime = true;
                        ent1.TimeActivity.Current.IsBillable = false;
                        ent1.TimeActivity.Current.ProjectID = Base.Project.Current.ContractID;
                        ent1.TimeActivity.Current.ProjectTaskID = projTID;          
                        ent1.Actions.PressSave();