在 x++ Dynamics 365 fin & ops 中向销售订单行插入固定运费

insert fixed freight charges to sales order lines in x++ Dynamics 365 fin & ops

我是 X++ 开发的新手,我想在销售订单行而不是销售订单抬头中插入运费。我使用了 SalesOrderLineChargeEntity 但它没有保存记录而是抛出错误。

private void addCharges()
{
    SalesOrderLineChargeV2Entity chargeEntity;

    boolean isNew;
    str saleschargecode = 'Freight';
    str saleschargecodedesc = 'Freight Charges';

    if(saleschargecode != '')
    {
        select forupdate chargeEntity  where chargeEntity.SalesOrderNumber=='22676' && chargeEntity.SalesChargeCode == saleschargecode && chargeEntity.ChargeLineNumber == 1;

        if(!chargeEntity)
        {
            isNew = true;
            chargeEntity.clear();
        }
        chargeEntity.ChargeCategory = MarkupCategory::Fixed;
        chargeEntity.SalesChargeCode = saleschargecode;
        chargeEntity.ChargeDescription=saleschargecodedesc;
        chargeEntity.ChargeAccountingCurrencyCode = _ecomIntSalesOrderImportStaging.currency_id;
        chargeEntity.ChargePercentage=0;
        chargeEntity.ExternalChargeAmount=0;
        chargeEntity.FixedChargeAmount= 230;
        chargeEntity.ChargeLineNumber=1;


        chargeEntity.SalesOrderNumber='22676';

        chargeEntity.SalesTaxGroupCode='AvaTax';
        chargeEntity.WillInvoiceProcessingKeepCharge=NoYes::No;
        chargeEntity.IsIntercompanyCharge = NoYes::No;

        if(isNew)
        chargeEntity.insert();
        else
        chargeEntity.update();
    }
}

这是我用来插入销售行运费的代码,但它会像图片中提到的那样抛出错误。

需要帮助。

谢谢, 桑迪

我可以通过分配我想显示运费的销售线的 InventoryLotId 来解决问题,我做了以下代码更改:

select firstonly salesOrderLine
                where salesOrderLine.SalesOrderNumber == '22676';
chargeEntity.SalesOrderLineInventoryLotId = salesOrderLine.InventoryLotId;