Solved

Setting Shipping Address on a Purchase Order

  • 11 October 2022
  • 3 replies
  • 240 views

Userlevel 1

Our client has a specific requirement to set the Shipping Address to the Branch Address for Purchase Orders that are of the Type = Project Drop Ship.  Currently, users are manually overriding the Ship To Address for these types of Orders and they have asked us to code it such that if the type of the Purchase Order is Project Drop Ship, then to set the Ship To Address equal to the Branch Address from the OTHER tab of the PO.  The following code does what we need it do; however, upon clicking save an error is generated.  The error is:

Error: Inserting ‘PO Shipping Address’ record raised at least one error.  Please review the errors.  Error: ‘RevisionID’ cannot be empty.

The following code does what it needs to do, but for the error when saving:

protected void POOrder_ProjectID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
  if(InvokeBaseHandler != null)
    InvokeBaseHandler(cache, e);
  var row = (POOrder)e.Row;
  var po_branchID = row.BranchID;
  var po_ordertype = row.OrderType;
  var po_projectID = row.ProjectID;
  //row.OrderDesc = po_ordertype;
  if (po_projectID != null && po_ordertype == "PD") {
    // Get the Branch Record
    Branch branch_record = PXSelect<Branch, Where<Branch.branchID, Equal<Required<Branch.branchID>>>>.Select(Base, row.BranchID);
    var branch_BaccountID = branch_record.BAccountID;
    if (branch_BaccountID != null) {
      // Get the Branch Business Account (Location) record to get its address ID
      Location branch_baccount = PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>.Select(Base, branch_BaccountID);
      var branch_DefAddressID = branch_baccount.DefAddressID;
      if (branch_DefAddressID != null) {
        // Get the Branch Business Account Address Record
        Address branch_address = PXSelect<Address, Where<Address.addressID, Equal<Required<Address.addressID>>>>.Select(Base, branch_DefAddressID);
        var branch_AddressID = branch_address.AddressID;
        if (branch_AddressID != null) {
          var branch_addressline1 = branch_address.AddressLine1;
          var branch_addressline2 = branch_address.AddressLine2;
          var branch_addressline3 = branch_address.AddressLine3;
          var branch_city = branch_address.City;
          var branch_state = branch_address.State;
          var branch_countryid = branch_address.CountryID;
          var branch_postalcode = branch_address.PostalCode;
          POShipAddress address = Base.Shipping_Address.Current = Base.Shipping_Address.Select();
          address.OverrideAddress = true;
          address = Base.Shipping_Address.Update(address);
          if (address == null)
          {
              address = Base.Shipping_Address.Current;
          }
          address.AddressLine1 = branch_addressline1;
          address.AddressLine2 = branch_addressline2;
          //address.AddressLine3 = branch_addressline3;
          address.City = branch_city;
          address.CountryID = "US";
          address = Base.Shipping_Address.Update(address);
          address.State = branch_state;
          address.PostalCode = branch_postalcode;
          Base.Shipping_Address.Update(address);
          Base.Actions.PressSave();
          Base.Shipping_Address.Update(address);
        }
      }
    }
  }
}

 

Anyone have any ideas how to get past the error?  Any help would be most appreciated.  Thanks!

 

 

icon

Best answer by Laura02 11 October 2022, 14:48

View original

3 replies

Badge +18

Hello,

I don’t write code, but I have an idea that I hope will help you.

I’m looking at the address table in SQL on my local demo. I see the Address table has a RevisionID field. When I make changes to addresses, Acumatica saves the old record and adds the new one as a new address record with a higher revision #.

I’m trying to read your code and see if you are selecting any particular Revision of the branch’s address when you “Get the Branch Address record”. Maybe you need to choose the address with the highest revision #? in addition to identifying with address id and default address id fields.

Good luck.

 

Badge +18

PS. If my idea doesn’t help you, maybe you want to ask the Moderators to move your question out of Financials and into Development area. 💡 

Userlevel 1

I moved to the development section.  Thanks!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved