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

Acumatica新手求助:如何在Graph层级设置字段为必填项

解决方案:关联Customer Locations与对象 + Graph层级必填字段设置

嘿,作为Acumatica新手能搞定基础定制还着手加自定义字段,已经很厉害了!针对你提到的两个核心需求——关联Customer Locations到相关对象、设置Graph层级的字段必填规则,我来分享下实操方案:

1. 关联Customer Locations到自定义/现有对象

在Acumatica里关联Customer Locations(也就是Location表),核心是通过外键关联+选择器来实现,不管是自定义DAC还是扩展现有系统对象都适用:

示例:在自定义DAC中添加关联字段

假设你有个记录硬件发货的自定义DAC(比如HardwareShipment),可以这样加关联字段:

using PX.Data;
using PX.Objects.CR;
using PX.Objects.AR;

public class HardwareShipment : IBqlTable
{
    // 其他字段...

    [PXDBInt]
    [PXForeignKey(typeof(Location))] // 建立数据库级别的外键关联,保证数据完整性
    [PXSelector(
        typeof(Search<Location.locationID, Where<Location.bAccountID, Equal<Current<BAccount.bAccountID>>>>),
        typeof(Location.locationCD), typeof(Location.descr),
        SubstituteKey = typeof(Location.locationCD) // 界面显示友好的位置编码而非ID
    )]
    [PXUIField(DisplayName = "Customer Location")]
    public virtual int? CustLocationID { get; set; }
    public abstract class custLocationID : PX.Data.BQL.BqlInt.Field<custLocationID> { }
}
  • PXForeignKey:防止引用不存在的Location,确保数据关联的有效性
  • PXSelector:自动过滤当前客户下的所有位置(通过Current<BAccount.bAccountID>关联当前客户),用户在界面上只能选该客户的有效地点
  • 如果是扩展现有对象(比如SOOrder),只需创建对应的DAC扩展类,把上面的字段加进去即可

界面配置

写完字段后,你可以通过Acumatica的Customization Project里的Layout Editor,把这个字段拖到对应的页面布局上,用户就能在界面上直观选择关联的客户地点了。

2. Graph层级的字段必填设置

如果需要在Graph层面控制字段必填(比如只有硬件发货场景才要求必填,或者全局必填),推荐用RowPersisting事件来实现,比直接在DAC上设静态必填更灵活:

示例:在自定义Graph中设置必填校验

假设你的硬件发货用的是自定义GraphHardwareShipmentEntry,可以这样加校验:

public class HardwareShipmentEntry : PXGraph<HardwareShipmentEntry, HardwareShipment>
{
    // 其他Graph代码...

    protected virtual void _(Events.RowPersisting<HardwareShipment> e)
    {
        if (e.Row == null) return;

        // 检查关联的客户位置字段是否为空
        if (e.Row.CustLocationID == null)
        {
            // 抛出错误,阻止保存并在界面显示提示
            e.Cache.RaiseExceptionHandling<HardwareShipment.custLocationID>(
                e.Row, 
                null, 
                new PXSetPropertyException("Customer Location is required for hardware shipments", PXErrorLevel.Error)
            );
        }
    }
}

扩展现有Graph的情况

如果是在现有系统Graph(比如SOOrderEntry)里加校验,就用Graph扩展类:

public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
    protected virtual void _(Events.RowPersisting<SOOrder> e)
    {
        if (e.Row == null) return;

        // 获取SOOrder的扩展字段(假设你已经给SOOrder加了CustLocationID)
        var orderExt = e.Row.GetExtension<SOOrderExtension>();
        
        // 可添加业务条件,比如只有订单类型为硬件发货时才校验
        if (e.Row.OrderType == "HARD" && orderExt.CustLocationID == null)
        {
            Base.Caches[typeof(SOOrder)].RaiseExceptionHandling<SOOrderExtension.custLocationID>(
                e.Row, 
                null, 
                new PXSetPropertyException("Customer Location is required for hardware shipments", PXErrorLevel.Error)
            );
        }
    }
}
  • RowPersisting事件会在数据保存前触发,确保必填字段校验通过才允许保存
  • 你可以根据业务逻辑添加额外条件(比如特定订单类型、特定状态),实现动态必填规则

同步遗留系统的小提示

关联好Customer Location后,你可以在RowPersisted事件里触发同步逻辑(比如调用遗留系统的API),确保Acumatica里的硬件发货数据保存完成后,再把包含Location信息的同步数据推送到遗留系统,避免数据不一致。

内容的提问来源于stack exchange,提问作者Aaron St Clair

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:28:13