Skip to main content

Hi there,

 

I am trying to override the Ship-to-Address and Ship-to-Contact details by making them automatically filled when I select Customer from a custom field in Shipments screen.

 

Further digging into this shown that the details is referencing from ShipAddressID and ShipContactID which is being referenced from CustomerID on the header. However for Transfer, the Customer selector on the header will be hidden and from SQL, it shows that the Customer is pointing to itself.

 

How do I get the ShipAddressID and ShipContactID to be referenced from the custom Customer field instead?

Hi @ericklasimin61  For the Customer ShipAddressID and ShipContactID, please refer the Location table. 

Here is the screenshot.

 


Hi @Naveen Boga , so I managed to populate the custom field UsrShipAddressID based on your recommendation.

My Extension:

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
        gPXDBInt]
        rPXUIField(DisplayName = "Ship Address ID")]
        lPXFormula(typeof(Selector<SOShipmentExt.usrCustomerID, Location.defAddressID>))]

        public virtual int?  UsrShipAddressID { get; set; }
        public abstract class usrShipAddressID : PX.Data.BQL.BqlInt.Field<usrShipAddressID> { }
        #endregion

        #region UsrShipContactID
        dPXDBInt]
        ÂPXUIField(DisplayName = "Ship Address ID")]
        /PXFormula(typeof(Selector<SOShipmentExt.usrCustomerID, Location.defContactID>))]

        public virtual int? UsrShipContactID { get; set; }
        public abstract class usrShipContactID : PX.Data.BQL.BqlInt.Field<usrShipContactID> { }
        #endregion
    }

 

My Event Handler:

  public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
  {
    #region Event Handlers
      protected void SOShipment_UsrCustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = (SOShipment)e.Row;
            if (row != null)
            {
                SOShipmentExt sOShipmentExt = row.GetExtension<SOShipmentExt>();
                SOShipment sOShipment = SOShipment.PK.Find(Base, row.ShipmentNbr);
                sOShipmentExt.UsrShipAddressID = sOShipment.ShipAddressID;
            }
        }
    #endregion
  }
}

 

However, how should I override the existing ShipAddressID and UsrShipAddressID and ultimately change the address details?


Sorry @Naveen Boga , the above code indeed managed to populate the UsrShipAddressID but it follows the document CustomerID, not UsrCustomerID. As for UsrCustomerID, I can’t seem to change the value to something else since it will always go back to the initial value. 


Hi @Naveen Boga , I managed to populate the Ship-to-Contact and Ship-to-Address fields by using the following code:

 

My DAC Extension:

    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
}

 

My Graph Extension:

    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
}

 

The issues I’m facing now

  1. Once the document has been saved and I switched to another document, I am unable to access back the previous document that has been saved and it returns below errors:

 

  1. If the selected Customer ID doesn’t have any data in SOShipmentAddress or SOShipmentContact, then it won’t allow me to select the customer. Ideally, I should be able to select the customer and the fields should be auto populated with address details from Address table.

I would appreciate any help since I’m getting really close to solving this.


Hi @ericklasimin61 have you been able to resolve your issue or do you still need assistance from @Naveen Boga ? Thank you!


Hi @Chris Hackett , I managed to solve one of the issues by implementing a workaround on them:

  1. I nulled both UsrShipAddressID and UsrShipContactID fields once the method to populate the Address and Contact details has been executed.
  2. Still not resolved. I would welcome any assistance on this.

Reply