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!