To specify Bill-To Contact and Bill-To Address info for a Sales Order, you should always first invoke Select()
method on the Billing_Contact and Billing_Address data views prior to assigning any field values. It is also recommended to assign the result of Select()
method to the Billing_Contact and Billing_Address data views' Current property to guarantee that your code modifies the current record in SOBillingContact and SOBillingAddress PXCache respectively.
When you need to override Bill-To Contact and Address info for a Sales Order, set correct values for the OverrideContact and OverrideAddress properties on the SOBillingContact DAC and the SOBillingAddress DAC. Don't forget to invoke Update()
method on the SOBillingContact and SOBillingAddress caches right after you updated OverrideContact and OverrideAddress properties to commit the changes. Once that's done, you can go ahead and specify Bill-To Contact and Address info for a Sales Order.
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public PXAction<SOOrder> UpdateBillingAddress;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Update Bill-To Info")]
protected void updateBillingAddress()
{
SOBillingContact contact = Base.Billing_Contact.Current = Base.Billing_Contact.Select();
if (contact.OverrideContact == true)
{
contact.OverrideContact = false;
Base.Billing_Contact.Update(contact);
}
else
{
contact.OverrideContact = true;
contact = Base.Billing_Contact.Update(contact);
if (contact == null)
{
contact = Base.Billing_Contact.Current;
}
contact.Phone1 = "+1 (908) 643-0281";
contact.Email = "[email protected]";
Base.Billing_Contact.Update(contact);
}
SOBillingAddress address = Base.Billing_Address.Current = Base.Billing_Address.Select();
if (address.OverrideAddress == true)
{
address.OverrideAddress = false;
Base.Billing_Address.Update(address);
}
else
{
address.OverrideAddress = true;
address = Base.Billing_Address.Update(address);
if (address == null)
{
address = Base.Billing_Address.Current;
}
address.AddressLine1 = "201 Lower Notch Rd";
address.AddressLine2 = "Office Suite 1936";
address.City = "Little Falls";
address.CountryID = "US";
address = Base.Billing_Address.Update(address);
address.State = "NJ";
address.PostalCode = "07425";
Base.Billing_Address.Update(address);
}
Base.Actions.PressSave();
}
}