【问题标题】:Acumatica PXUIFieldAttribute SetError giving errorAcumatica PXUIFieldAttribute SetError 给出错误
【发布时间】:2017-01-07 06:42:34
【问题描述】:

我正在尝试验证输入到我的Support Split 表中的值,为什么我无法获取我的ItemExtension?

protected void atcProjectCostCenterTable_CostCenterSplit_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldVerifying InvokeBaseHandler)
{
    if (InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
    var row = (atcProjectCostCenterTable)e.Row;

    if (row.ContractID > 0)
    {
        decimal? hun = 100;
        PX.Objects.CT.ContractExt item = row.GetExtension<PX.Objects.CT.ContractExt>();

        if (CostCenterSplit.Select().Count >= 1)
        {
            if (item.UsrCostCenterSum.Value != hun)
            {
                PXUIFieldAttribute.SetError<atcProjectCostCenterTable.costCenterSplit>(cache, row, "Support Percentages must equal 100%");
                //throw new PXSetPropertyException("Cost Center Percentages must equal 100%", PXErrorLevel.Warning);
            }
        }
    }
}

【问题讨论】:

  • ContractExt 真的是 atcProjectCostCenterTable 的扩展吗?请向我们提供这些类定义
  • 它是Contract的扩展,公共类ContractExt:PXCacheExtension{
  • 假设 row 是 atcProjectCostCenterTable 类型(当我们查看您的代码时应该是这种情况),调用类似于 row.GetExtension();会给你这个错误,因为 ContractExt 不是 atcProjectCostCenterTable 的扩展
  • 请参阅 T300 acumaticaopenuniversity.com/pdf/… DAC 扩展部分(第 185 页)

标签: acumatica


【解决方案1】:

尼克,请更换

PX.Objects.CT.ContractExt item = row.GetExtension<PX.Objects.CT.ContractExt>();

与

PX.Objects.CT.ContractExt item = Base.Project.Current.GetExtension<PX.Objects.CT.ContractExt>();

或

PX.Objects.CT.ContractExt item = Base.Project.Cache.GetExtension<PX.Objects.CT.ContractExt>(Base.Project.Current);

您当前的代码无法运行,因为 ContractExt 扩展了 Contract DAC,而不是 atcProjectCostCenterTable。由于 PMProject 继承自 Contract,因此为 Contract DAC 定义的 DAC 扩展也可用于 PMProject 实例。

【讨论】:

    【解决方案2】:
      Contract con = Base.Project.Current;
      PX.Objects.CT.ContractExt item = con.GetExtension<PX.Objects.CT.ContractExt>();
    

    【讨论】:

    • 最好在代码中包含一些上下文/解释,因为这会使答案对 OP 和未来的读者更有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多