You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Acumatica:如何在Graph层级将ExpirationDate字段设为必填?

解决Acumatica中CRQuote.ExpirationDate字段设为必填的问题

问题背景

需要将CRQuote数据类的ExpirationDate字段在界面设为必填,尝试两种自定义属性方式后,表单仍允许字段为空:

原字段属性:

[PXDBDate(BqlField = typeof(Standalone.CRQuote.expirationDate))]
[PXMassUpdatableField]
[PXUIField(DisplayName = "Expiration Date", Visibility = PXUIVisibility.SelectorVisible)]

尝试的无效方式:

  • 方式一:通过PXCustomizeBaseAttribute修改PXUIFieldAttribute的Required属性
  • 方式二:添加PXDefault并设置PersistingCheck

解决方案

需同时配置界面必填标记和后台数据校验,并确保属性合并方式正确,具体实现如下:

正确的CacheAttached代码

在CRQuoteEntry图的扩展类中添加以下代码:

public class CRQuoteEntryExtension : PXGraphExtension<CRQuoteEntry>
{
    [PXMergeAttributes(Method = MergeMethod.Merge)]
    [PXUIField(DisplayName = "Expiration Date", Visibility = PXUIVisibility.SelectorVisible, Required = true)]
    [PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]
    protected virtual void CRQuote_ExpirationDate_CacheAttached(PXCache cache)
    {
    }
}

关键说明

  1. 属性合并方式:使用MergeMethod.Merge而非Append,确保Required = true覆盖原PXUIFieldAttribute的默认设置,而非仅追加属性。
  2. 双重校验逻辑:
    • PXUIField(Required = true):在界面标记字段为必填,阻止用户提交空值
    • PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank):在后台校验数据,确保字段不为空时才允许保存
  3. Graph扩展位置:必须将CacheAttached方法放在CRQuoteEntry的扩展类中——该图是维护CRQuote记录的主界面,只有此处的属性修改会作用到表单。

替代方案(使用PXCustomizeBaseAttribute)

若坚持用PXCustomizeBaseAttribute,需确保合并方式正确,代码如下:

public class CRQuoteEntryExtension : PXGraphExtension<CRQuoteEntry>
{
    [PXMergeAttributes(Method = MergeMethod.Merge)]
    [PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), "Required", true)]
    [PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]
    protected virtual void CRQuote_ExpirationDate_CacheAttached(PXCache cache)
    {
    }
}

内容的提问来源于stack exchange,提问作者Amit Ranjan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 02:05:16