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

Acumatica发货屏幕定制报错:SOShipLine.ShippedQty属性被当作类型使用

解决Acumatica ERP发货屏幕定制的编译错误

我帮你梳理下问题和解决方案:你在Acumatica的发货(Shipment)屏幕做定制,想要在插入发货行时把OpenOrderQty的值复制到ShippedQty里,写了RowInserting事件的代码,但发布时遇到了编译错误。

你的原代码:

public void SOShipLine_RowInserting(PXCache sender, PXRowInsertingEventArgs e, PXRowInserting baseMethod) { 
    if (baseMethod != null) baseMethod(sender, e); 
    SOShipLine line = e.Row as SOShipLine; 
    if (line == null) return; // just in case 
    if (line.ShippedQty == 0) { 
        sender.SetValueExt<SOShipLine.ShippedQty>(line, line.OpenOrderQty); 
    } 
}

遇到的错误:

\App_RuntimeCode\SOShipmentEntry.cs(85): error CS0118: 'PX.Objects.SO.SOShipLine.ShippedQty' is a 'property' but is used like a 'type'

错误原因

Acumatica的SetValueExt<T>方法里的泛型参数T,需要传入的是DAC中定义的字段类(也就是继承自PX.Data.BQL.BqlField的抽象类),而不是实体类的属性。你这里用的SOShipLine.ShippedQty是实体类的属性(对应数据库列的get/set访问器),不是合法的泛型参数类型,所以编译器报错了。

修正后的代码

把泛型参数改成DAC里定义的字段类(通常是小写开头的同名字段,可查看DAC源码确认准确名称),修正后的代码如下:

public void SOShipLine_RowInserting(PXCache sender, PXRowInsertingEventArgs e, PXRowInserting baseMethod) 
{ 
    if (baseMethod != null) 
        baseMethod(sender, e); 

    SOShipLine line = e.Row as SOShipLine; 
    if (line == null) 
        return; 

    if (line.ShippedQty == 0) 
    { 
        // 将SOShipLine.ShippedQty替换为SOShipLine.shippedQty
        sender.SetValueExt<SOShipLine.shippedQty>(line, line.OpenOrderQty); 
    } 
}

额外说明

在Acumatica的DAC定义中,每个属性都会对应一个字段类,比如SOShipLine里的ShippedQty属性,对应的字段类定义大概是这样的:

public abstract class shippedQty : PX.Data.BQL.BqlDecimal.Field<shippedQty> { }

[PXDBQuantity(MinValue = 0, DisplayName = "Shipped Qty")]
[PXDefault(TypeCode.Decimal, "0.0")]
public virtual decimal? ShippedQty { get; set; }

所以在使用SetValueExt、SetValue这类需要指定字段的方法时,必须传入这个抽象字段类作为泛型参数,而不是属性名。

内容的提问来源于stack exchange,提问作者Untung Rohwadi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 04:17:11