Skip to main content

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!

 

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();

 


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!


Wondering if anyone has any insight into the above discussion?


Wondering if anyone has any insight into the above discussion?

I had a project with custom screen I tried couple of different ways to override and finally this worked for me
 

POShipContact shipContact = graph.Shipping_Contact.Select();
if (currentRequisition.SiteContact != null || currentRequisition.SitePhone != null)
{
    graph.Shipping_Contact.Cache.MarkUpdated(shipContact);
    if(currentRequisition.SiteContact != null)
    {
        shipContact.Attention = currentRequisition.SiteContact;
    }
    if(currentRequisition.SitePhone != null)
    {
        shipContact.Phone1 = currentRequisition.SitePhone;
    }
    graph.Shipping_Contact.Cache.MarkUpdated(shipContact);
    graph.Shipping_Contact.Cache.Persist(PXDBOperation.Update);
    shipContact.OverrideContact = true;
}
POShipAddress shipAddress = graph.Shipping_Address.Select();
if (currentRequisition.AddressLine1 != null)
{
    graph.Shipping_Address.Cache.MarkUpdated(shipAddress);
    shipAddress.AddressLine1 = currentRequisition.AddressLine1;
    shipAddress.AddressLine2 = currentRequisition.AddressLine2;
    shipAddress.City = currentRequisition.City;
    shipAddress.CountryID = currentRequisition.CountryID;
    shipAddress.State = currentRequisition.State;
    shipAddress.PostalCode = currentRequisition.PostalCode;

    graph.Shipping_Address.Cache.MarkUpdated(shipAddress);
    graph.Shipping_Address.Cache.Persist(PXDBOperation.Update);
    shipAddress.OverrideAddress = true;
}


Reply