Acumatica-独特支票

问题描述

什么属性可用于允许唯一值, 我们使用了[PXUniqueCheck(typeof(Name))] 但是,如果使用列表视图并且记录使用相同的名称进行更新,则它允许使用相同的名称值

更多详细信息- 嗨,列标记为IsKey = True的名称,我的视图是ListView,具有2个字段名称和描述,其中名称具有IsKey = True,另一个列ID具有DBIdentity属性。所以我认为DAC,UI添加行为都可以,在添加现有值时,它会使用新添加的值描述更新旧行,因为Name is Same。更新行为-将名称列更改为与其他列相同的值,然后允许两行具有相同的键,但是两行在UI上显示相同的描述,但在DB中有两行具有相同的名称值和不同的描述>

DAC-

[System.SerializableAttribute()]
[PXPrimaryGraph(typeof(TestCategoryMaint))]
public class TestCategory : PX.Data.IBqlTable
{

    #region TestCategoryID
    public abstract class testCategoryID : PX.Data.BQL.BqlInt.Field<testCategoryID>
{
    }
    protected int? _TestCategoryID;
    [PXDBIdentity()]
    [LicenseExpiration]
[PXReferentialIntegrityCheck]

public virtual int? TestCategoryID
    {
        get
        {
            return this._TestCategoryID;
        }
        set
        {
            this._TestCategoryID = value;
        }
    }
    #endregion

    #region Name
    public abstract class name : PX.Data.IBqlField
    {
    }
    protected string _Name;
    [PXDBString(50,IsKey = true,IsUnicode = true,InputMask = "")]
    [PXDefault()]        
    [PXUIField(DisplayName = "Test Category")]
    [PXCheckUnique(typeof(name))]
    public virtual string Name
    {
        get
        {
            return this._Name;
        }
        set
        {
            this._Name = value;
        }
    }
    #endregion

    #region Description
    public abstract class description : PX.Data.IBqlField
    {
    }
    protected string _Description;
    [PXDBString(255,IsUnicode =true)]
    [PXUIField(DisplayName = "Description")]
    public virtual string Description
    {
        get
        {
            return this._Description;
        }
        set
        {
            this._Description = value;
        }
    }
#endregion

解决方法

没有所尝试代码的任何示例,很难确保答案符合您的问题,但是我将尝试在广泛的范围内进行回答。

在上面的注释的基础上,标识字段之所以特别如此,是因为它在数据库中定义为 identity 。 DAC中的相应字段应标记为PXDBIdentity。在Acumatica中,通常将其定义为身份“ ID”字段。您显示的应保持唯一性的字段通常是代码“ CD”字段。

下面的示例显示如何设置对,并附有常用属性。在此示例中,“ CD”字段是自动编号的,但不是必须的。字段本身上的PXSelector 有助于将其保持为唯一值,因为它将允许您从现有值中选择,输入新值或检索键入的值。实际唯一性由标记为 IsKey = true 的所有字段的组合控制。

// This is the Identity field in the database (Use PXDBIdentity)
#region RequisitionID
[PXDBIdentity]
public virtual int? RequisitionID { get; set; }
public abstract class requisitionID
    : PX.Data.BQL.BqlInt.Field<requisitionID> { }
#endregion

// This is the user friendly Code (CD) to be unique (IsKey = true)
#region RequisitionCD
[PXDBString(30,IsKey = true,IsUnicode = true,InputMask = "")]
[PXDefault]
[AutoNumber(typeof(SSRQSetup.requisitionNumberingID),typeof(AccessInfo.businessDate))]
[PXSelector(
    typeof(SSRQRequisition.requisitionCD),typeof(SSRQRequisition.requisitionCD),typeof(SSRQRequisition.descr)
    )]
[PXUIField(DisplayName = Messages.FldRequisitionCD)]
public virtual string RequisitionCD { get; set; }
public abstract class requisitionCD
    : PX.Data.BQL.BqlString.Field<requisitionCD> { }

类似地,您可以参考此组合,以便在与用户交互时使用唯一的CD字段,但是ID值存储在记录中。最佳做法是使用ID字段在所有用于规范化数据库的表之间共享,并允许更改显示(CD)值而不必更新可能的其他几十个表。这意味着任何唯一对象(项目,供应商,客户等)都将保留在其自己的记录中,其中IsKey值唯一地标识确切的对象。如果您需要特定的表以将该值保持为 唯一性,则它将是唯一标记为 IsKey = true 的字段,然后将identity字段用于其他表引用这些数据。

要在其他表中使用此关键数据,应存储ID字段值,但使用PXSelector向用户展示CD值。这样可以在数据库中的相关表中存储非常有效的数值,而不是可能是几个字符或数千个字符的值(在极端情况下)。

#region RequisitionID
[PXDBInt]
[PXSelector(
    typeof(SSRQRequisition.requisitionID),typeof(SSRQRequisition.descr),SubstituteKey = typeof(SSRQRequisition.requisitionCD)
    )]
[PXUIField(DisplayName = Messages.FldRequisitionID)]
public virtual int? RequisitionID { get; set; }
public abstract class requisitionID
    : PX.Data.BQL.BqlInt.Field<requisitionID> { }
#endregion

了解IsKey的使用将根据您指定的每个字段推动唯一性,这一点非常重要。 IsKey将仅确保标记有 IsKey = true 的所有字段的唯一性。 PXSelector似乎确保该字段本身保持唯一,并且由SubstituteKey指定的字段在用作选择器时将检索具有您输入的值的记录。我只在ID与CD的情况下使用过,但是如果您有一些用例超出此答案的范围,则可以尝试使用PXSelector和IsKey。

,

下面的代码将帮助您仅添加唯一值,当您尝试添加重复值时,这将引发错误。

[PXCheckUniqueCustomError("Order already exists with Customer Order Nbr {0} and External Ref.Nbr {1}",typeof(SOOrder.customerOrderNbr),typeof(SOOrder.customerRefNbr),Where = typeof(Where2<Where<SOOrder.orderType,Equal<Current<SOOrder.orderType>>,And<SOOrder.customerOrderNbr,Equal<Current<SOOrder.customerOrderNbr>>,And<SOOrder.customerRefNbr,Equal<Current<SOOrder.customerRefNbr>>>>>,And<SOOrder.status,NotEqual<SOOrderStatus.cancelled>>>))]

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...