I have custom fields setup on DAC extensions for our sales orders and invoices. I am trying to update our SOShipmentEntry graph to copy the custom field from the Sales Order to the Invoice that is being created.
I haven’t added many custom fields to Invoices so I used the customization UI to create the new field. That new field ended up being added to an extension on ARRegister.
In the customization I’m working on we already have an InvoiceShipment Delegate setup that is responsible for copying an Address Line 4 for both Billing and Shipping addresses. This delegate does exactly what it should and has been working for a long time.
I’ve found a number of other posts here covering a similar concept from the SOOrderEntry side of things but so far haven’t found something that works when invoices are created from SOShipmentEntry. Given that we’re already successfully copying Address Line 4 to the addresses on invoices, I didn’t think I’d have a big problem making this work.
My problem is that while my code is able to find the SOOrder custom field and set that same value on our ARRegister DAC Extension, the data is not saved to the database.
I’ll share some of my code in case any of that seems like it might be the issue. For what it is worth, not all of this is my code and was created by our original implementation partner. I’m going to omit anything not related to this direct issue
DAC Extension for ARRegister
public class PorchlightARRegisterExt : PXCacheExtension<PX.Objects.AR.ARRegister>
{
#region UsrPBCCustomerPO
[PXString(255)]
[PXUIField(DisplayName="Customer PO")]
public virtual string UsrPBCCustomerPO { get; set; }
public abstract class usrPBCCustomerPO : PX.Data.BQL.BqlString.Field<usrPBCCustomerPO> { }
#endregion
}
SOShipmentEntry Graph Extension
public delegate void InvoiceShipmentDelegate(SOInvoiceEntry docgraph
, SOShipment shiporder
, DateTime invoiceDate
, InvoiceList list
, PXQuickProcess.ActionFlow quickProcessFlow);
[PXOverride]
public void InvoiceShipment(SOInvoiceEntry docgraph
, SOShipment shiporder
, DateTime invoiceDate
, InvoiceList list
, PXQuickProcess.ActionFlow quickProcessFlow
, InvoiceShipmentDelegate baseMethod)
{
baseMethod(docgraph, shiporder, invoiceDate, list, quickProcessFlow);
string pxmessagePrefix = "Sales Order -> Shipper -> Invoice Update: ";
var doc = docgraph.CurrentDocument.Current;
doc = SetInvoiceCustomerPOs(shiporder, doc, docgraph);
// Address 4 code for Shipping Address
// Address 4 code for Billing Address
}
private ARInvoice SetInvoiceCustomerPOs(SOShipment shiporder, ARInvoice invoice, SOInvoiceEntry docgraph)
{
var invoiceExt = invoice.GetExtension<PorchlightARRegisterExt>();
if (invoiceExt == null) return invoice;
if (!string.IsNullOrEmpty(invoiceExt?.UsrPBCCustomerPO)) return invoice;
var customerPOs = new List<string>();
foreach (PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact> res in
OrderListFromShipper.Select(shiporder.ShipmentNbr, shiporder.ShipmentType))
{
var order = (SOOrder)res;
var orderExt = order.GetExtension<PorchlightSOOrderExt>();
if (!string.IsNullOrEmpty(orderExt?.UsrPBCCustomerPO))
{
customerPOs.Add(orderExt.UsrPBCCustomerPO);
}
}
if (!customerPOs.Any()) return invoice;
invoiceExt.UsrPBCCustomerPO = string.Join(", ", customerPOs);
// This runs fine but does not save data to the ARRegister table in the DB
invoice = docgraph.CurrentDocument.Update(invoice);
docgraph.Save.Press();
return invoice;
}
Querying the ARRegister table manually with SSMS shows that the custom field is not being populated. I’m kind of stumped here; this seems like it should work but I’m obviously missing some nuance of working with custom fields and ARRegister plus its derived implementations.
We’re currently on Acumatica 23R1, if that makes a difference.
As an aside, I know sales orders already have a CustomerOrderNbr field that could hold Customer PO numbers. We’ve been using that field for this very purpose for years. However, we’re about to move our main web site to Shopify and the connector wants to use CustomerOrderNbr for the Shopify web order information. This is actually fine for the order types we’re importing from Shopify.
However, it seems that when an export only order type gets sent to Shopify, the CustomerOrderNbr field on the sales order gets overwritten with the Shopify order number, just like the import order type. This means that for non-web orders we want people to see status updates of on Shopify, any customer PO numbers get overwritten which will be a problem for our corporate customers being billed on account. So, we need this new alternate field to hold our customer provided PO numbers so they can be exported to the site and still show the customer that number on invoice reports.