【问题标题】:Saving custom table error : Specified cast is not valid保存自定义表错误:指定的转换无效
【发布时间】:2018-01-16 23:15:36
【问题描述】:

我有一个自定义 DAC 来保存物品的不同分店价格。

当我尝试保存库存项目时,我收到“指定的演员表无效”错误:

我不确定 Branch 属性之一是否有问题。

这是我的 DAC

using System;
using PX.Data;
using PX.Objects.IN;
using PX.Objects.GL; 


namespace SalePriceByBranch
{
  [Serializable]
  public class INItemPriceByBranch: IBqlTable
  {

    [PXDBInt(IsKey = true)]
    [PXUIField(DisplayName = "Inventory ID")]
    [PXParent(typeof(Select<InventoryItem, Where<InventoryItem.inventoryID, Equal<Current<INItemPriceByBranch.inventoryID>>>>))]
    [PXDBDefault(typeof(InventoryItem.inventoryID))]
    public Int32? InventoryID { get; set; }
    public class inventoryID : IBqlField{}      

    [PXDBInt(IsKey=true)]
    [PXUIField(DisplayName = "Branch")]
    [PXDefault(0)]
    [Branch()]
    public Int32? BranchID{ get; set; }
    public class branchID : IBqlField{}          


    [PXDBDecimal(4)]
    [PXUIField(DisplayName = "Unit Price")]
    [PXDefault(TypeCode.Decimal,"0.0")]
    public Decimal? UnitPrice { get; set; }
    public class unitPrice : IBqlField{}        

  }
}

我认为 BranchID 上的错误是一个红鲱鱼。这是错误跟踪:

有什么想法吗?感谢您的回复!

【问题讨论】:

  • 您输入分行名称吗? (上例中为 AKL,MAIN。)如果不是,它们是如何设置的?
  • 可以直接输入,可以。但它也可以弹出分支查找对话框。

标签: acumatica


【解决方案1】:

Branch 属性已将其类型定义为 PXDBInt/PXInt(见下文)。当使用 [Branch]、[Inventory]、[Customer] 等内置属性时...我避免重新定义类型,因为它有时会引发运行时错误。

[PXDBInt()]
[PXInt]
[PXUIField(DisplayName = "Branch", FieldClass = _FieldClass)]
[PXRestrictor(typeof(Where<Branch.active, Equal<True>>), Messages.BranchInactive)]
public class BranchAttribute : AcctSubAttribute, IPXFieldSelectingSubscriber
{
   [...]
}

您可以将 BranchID 声明为 Branch 属性中的关键字段,而不是使用 PXDBInt:

[Branch(null, IsKey = true)]

另一种可能性是 [PXDefault(0)] 中的值 0 无法解析为系统中的 BranchID 0。这应该很容易在数据库中查找,因为 SalesDemo DB 分支从 16 开始。分支属性比标准自定义字段具有更多逻辑,它可以具有防止无效分支编号的验证逻辑。

如果您需要初始化 Branch 属性,请考虑在 Branch 属性中而不是 PXDefault 中进行:

[Branch(typeof(APRegister.branchID))]

Branch 属性还包含一个带有“Branch”显示名称的 PXUIField,因此如果您希望将该字段标记为“Branch”,则无需重新定义它。

最后,DAC 字段支持类在 Acumatica 中按约定声明为抽象。

所有这些更改都应用于您的 DAC 字段:

[Branch(null, IsKey=true)]
public abstract class branchID : IBqlField { }  
public Int32? BranchID { get; set; }

【讨论】:

    猜你喜欢
    • 2020-01-02
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 2013-08-27
    相关资源
    最近更新 更多