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) { } }
关键说明
- 属性合并方式:使用
MergeMethod.Merge而非Append,确保Required = true覆盖原PXUIFieldAttribute的默认设置,而非仅追加属性。 - 双重校验逻辑:
PXUIField(Required = true):在界面标记字段为必填,阻止用户提交空值PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank):在后台校验数据,确保字段不为空时才允许保存
- 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
相关产品推荐
相关产品推荐

