【问题标题】:How to default the Project Description with the "CustomerID"如何使用 \"CustomerID\" 来默认项目描述
【发布时间】:2022-10-20 03:09:13
【问题描述】:

我试图在项目描述的开头插入客户 ID。我相信这样做的两个机会是 1)在选择客户时和 2)如果客户已经被选择,则在选择模板时。我也相信我想扩展 PM.ProjectEntry 业务逻辑。我有两个问题:

  1. 当我尝试在 CustomerID 字段更新事件中选择客户记录时,使用扩展中源代码中的相同代码会给我一个错误。该错误在下面的代码中标识。

  2. 我有一个 TemplateID 字段更新事件,我认为是 DefaultFromTemplateProjectSettings 事件的扩展。没有错误,但描述字段没有被修改。

    namespace PX.Objects.PM
    {
      public class ProjectEntry_Extension : PXGraphExtension<PX.Objects.PM.ProjectEntry>
      {
        #region Event Handlers
      
        // Attempt to modify the project description line after a customer has been selected
        protected virtual void _(Events.FieldUpdated<PMProject, PMProject.customerID> e, PXFieldUpdated baseMethod)
        {
          baseMethod(e.Cache, e.Args);
    
          if (e.Row != null)
          {
            // Line 3 of this select statement errors with:
            // Argument 1: cannot convert from 'PX.Objects.PM.ProjectEntry_Extension' to 'PX.Data.PXGraph'
            Customer customer = new PXSelect<Customer,
              Where<Customer.bAccountID,
              Equal<Required<Customer.bAccountID>>>>(this).Select(e.Row.CustomerID);
            
            if (customer != null)
            {
              e.Cache.SetValueExt<PMProject.description>(e.Row, customer.AcctCD + " " + e.Row.Description);
            }
          }
        }
    
        // Two attempts to modify the project descrition after the project template has been selected
        // Neither of these two codes error, they just don't update the project description field
        // "customer.AcctCD" would be determined similar to the above process that currently errors
        protected virtual void DefaultFromTemplateProjectSettings(PMProject prj, PMProject templ)
        {
          prj.Description = "customer.AcctCD" + ": " + templ.Description;
        }
          
        protected virtual void _(Events.FieldUpdated<PMProject, PMProject.templateID> e, PXFieldUpdated baseMethod)
        {
          baseMethod(e.Cache, e.Args);
    
          if (e.Row != null)
          {
            e.Cache.SetValueExt<PMProject.description>(e.Row, "customer.AcctCD" + ": " + e.Row.Description);
          }
        }
          
        #endregion
      }
    }
    

    在 PM.ProjectEntry 业务逻辑中,我发现了以下内容:

        protected virtual void OnCopyPasteTasksInserted(ProjectEntry target, Dictionary<int, int> taskMap)
        {
            //this method is used to extend Copy in Customizations.
        }
    

    所以,我在我的定制中尝试了以下内容。没有错误,但在选择模板时不会改变项目描述。

        protected virtual void OnDefaultFromTemplateTasksInserted(PMProject prj, PMProject templ, Dictionary<int, int> taskMap)
    {
      prj.Description = "CustomerID: " + templ.Description;
    }
    

    没有“CustomerID:”,即 DefaultFromTemplateProjectSettings 对象中使用的代码行。

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    关于第一个错误,你只需要换行

    Customer customer = new PXSelect<Customer,
          Where<Customer.bAccountID,
          Equal<Required<Customer.bAccountID>>>>(this).Select(e.Row.CustomerID);
    

    Customer customer = new PXSelect<Customer,
          Where<Customer.bAccountID,
          Equal<Required<Customer.bAccountID>>>>(this.Base).Select(e.Row.CustomerID);
    

    您需要将PXGraph 实例传递给PXSelect 构造函数,而您当前正在传递this,即PXGraphExtension

    关于第二部分,我认为匿名事件处理程序没有 BaseMethod 的概念,所以我会尝试删除该函数的第二个参数。

    【讨论】:

    • 您对第一个错误的回答解决了这个问题。
    • 在第二个错误中,我在 PM.ProjectEntry 业务逻辑中发现了这段代码的 sn-p: protected virtual void OnCopyPasteTasksInserted(ProjectEntry target, Dictionary<int, int> taskMap) { //此方法用于扩展 Customizations 中的 Copy。所以,我在我的定制中尝试了这个。没有错误,只是不起作用。 protected virtual void OnDefaultFromTemplateTasksInserted(PMProject prj, PMProject templ, Dictionary<int, int> taskMap) { prj.Description = "CustomerID:" + templ.Description; }
    猜你喜欢
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 2017-01-02
    相关资源
    最近更新 更多