通过 UDF 覆盖送货联系人和地址

Override Ship-To Contact & Address via UDF

我有一个要求 Ship-to Contact & AddressShipments 屏幕上(对于 Transfer only) 将被使用 Customer select 从 UDF 编辑的位置覆盖。

The UDF that I have created

一段我用来测试的代码:

    #region AddressLine1  
    [PXMergeAttributes(Method = MergeMethod.Merge)]
    [PXDBScalar(typeof(Search2<SOAddress.addressLine1,
        InnerJoin<SOShipment, On<SOAddress.customerID, Equal<SOShipment.customerID>>,
            InnerJoin<BAccount, On<BAccount.bAccountID, Equal<SOShipment.customerID>>,
        InnerJoin<SOShipmentKvExt, On<SOShipment.noteID, Equal<SOShipmentKvExt.recordID>>>>>,
            Where<BAccount.acctCD, Equal<Current<SOShipmentKvExt.valueString>>>>))]
    public string AddressLine1 { get; set; }
    #endregion

使用上面的代码,地址行 1 字段保持为空,尽管 UDF 中的客户正在 selected。

我希望能有一个易于理解的解释,因为我是 C# 的新手。谢谢!

编辑:

我使用以下代码成功地填充了 Ship-to-Contact 和 Ship-to-Address 字段:

我的 DAC 扩展:

    public class SOShipmentExt : PXCacheExtension<PX.Objects.SO.SOShipment>
{
    #region UsrCustomerID

    [CustomerActive(DescriptionField = typeof(Customer.acctName))]
    [PXUIField(DisplayName = "Customer ID")]
    [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
    public virtual int? UsrCustomerID { get; set; }
    public abstract class usrCustomerID : PX.Data.BQL.BqlInt.Field<usrCustomerID> { }

    #endregion


    #region UsrShipAddressID

    [PXDBInt()]
    [PXUIField(DisplayName = "Ship Address ID")]
    public virtual Int32? UsrShipAddressID { get; set; }
    public abstract class usrShipAddressID : PX.Data.BQL.BqlInt.Field<usrShipAddressID> { }

    #endregion


    #region UsrShipContactID

    [PXDBInt()]
    [PXUIField(DisplayName = "Ship Contact ID")]
    public virtual Int32? UsrShipContactID { get; set; }
    public abstract class usrShipContactID : PX.Data.BQL.BqlInt.Field<usrShipContactID> { }

    #endregion
}

我的图表扩展:

    public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
    #region Event Handlers

   public virtual void SetShipAddressAndContact(SOShipment shipment, int? shipAddressID, int? shipContactID)
    {
        SOShipmentExt sOShipmentExt = shipment.GetExtension<SOShipmentExt>();

        foreach (SOShipmentAddress address in Base.Shipping_Address.Select())
        {
            if (address.AddressID < 0)
            {
                Base.Shipping_Address.Delete(address);
            }
        }

        foreach (SOShipmentContact contact in Base.Shipping_Contact.Select())
        {
            if (contact.ContactID < 0)
            {
                Base.Shipping_Contact.Delete(contact);
            }
        }            
    }


    protected virtual void SOShipment_UsrCustomerID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
    {
        SOShipment row = (SOShipment)e.Row;
        SOShipmentExt sOShipmentExt = row.GetExtension<SOShipmentExt>();

        SOShipmentAddress sOShipment = SelectFrom<SOShipmentAddress>.Where<SOShipmentAddress.customerID.IsEqual<@P.AsInt>>.View.Select(this.Base, sOShipmentExt.UsrCustomerID);

        SOShipmentContact sOShipmentContact = SelectFrom<SOShipmentContact>.Where<SOShipmentContact.customerID.IsEqual<@P.AsInt>>.View.Select(this.Base, sOShipmentExt.UsrCustomerID);

        if (row != null && sOShipmentExt != null)
        {
            sOShipmentExt.UsrShipAddressID = sOShipment.AddressID;
            sOShipmentExt.UsrShipContactID = sOShipmentContact.ContactID;
        }

        SetShipAddressAndContact(row, sOShipmentExt.UsrShipAddressID, sOShipmentExt.UsrShipContactID);


    #endregion
}

我现在面临的问题:

  1. 文档保存后我切换到另一个文档,我无法访问之前保存的文档并且它 returns 以下错误: ShipAddressID - Specified cast is not valid ShipContactID - Specified cast is not valid

  2. 如果 selected 客户 ID 在 SOShipmentAddress 或 SOShipmentContact 中没有任何数据,那么它将不允许我 select 客户。理想情况下,我应该能够 select 客户并且字段应该自动填充来自地址 table.

    的地址详细信息

我将不胜感激任何帮助,因为我已经非常接近解决这个问题了。

SOAddress 是链接到 SO 和货运的 table 地址。由于此数据通常不会发生太大变化,因此我们的想法是将记录链接到多个 SO 和发货。当客户的地址发生变化时,会在 SOAddress 中创建一条新记录。这样,历史数据就完好无损地保存了下来。因此,不应编辑 table 中的记录。因此,与其考虑覆盖 SOAddress 中的地址信息,不如考虑将链接到 Shipment 的 ShipAddressID 覆盖到您创建的新地址或更可能是已经存在的地址。