Question

Setting Shipping Address on a Purchase Order - Customization

  • 11 October 2022
  • 3 replies
  • 153 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!

 


3 replies

Userlevel 4
Badge +2

In your fieldUpdated event handler I noticed that you are calling   “Base.Actions.PressSave(); “ which is not recommended. In that event you can set your Shipping_Address (in the cache) and not call “Base.Actions.PressSave();” then you could use the Form’s Save button to save/persist all the changes. If you need to refresh a view for the address try something like:  “  Base.Shipping_Address.View.RequestRefresh();

 

Userlevel 1

Cesar:

Thanks for the reply.  I made the recommended change; however, this did not work.  Rather than re-produce the code, I will just add the section that I changed.

              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.View.RequestRefresh();
              Base.Shipping_Address.Update(address);

(Note that I dd try removing the “Base.Shipping_Address.Update(address);” as well, but this also did not work) 

When it has the PressSave method the PO screen will look like this:


which is how they want it; however, with the “Base.Shipping_Address.View.RequestRefresh();” call. the screen looks like the following and the Project Address is persisted (which is the default behavior that I am trying to change):

 

Is there some alternative to “Base.Shipping_Address.View.RequestRefresh();” that I should be using?  Thanks again!

Userlevel 1

Wondering if anyone has any insight into the above discussion?

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