How to paste custom field values from Sales Order details to Shipment and AR Invoice?

I have created a custom DB-bound field, called Specialist, in the SOLine, SOShipLine, and ARTran DACs:

public class SOLineExt : PXCacheExtension<PX.Objects.SO.SOLine>
{
    public class usrSpecialist : IBqlField { }

    [PXDBString(60)]
    [PXUIField(DisplayName = "Specialist")]
    public string UsrSpecialist { get; set; }
}

public class SOShipLineExt : PXCacheExtension<PX.Objects.SO.SOShipLine>
{
    public class usrSpecialist : IBqlField { }

    [PXDBString(60)]
    [PXUIField(DisplayName = "Specialist")]
    public string UsrSpecialist { get; set; }
}

public class ARTranExt : PXCacheExtension<PX.Objects.AR.ARTran>
{
    public class usrSpecialist : IBqlField { }

    [PXDBString(60)]
    [PXUIField(DisplayName = "Specialist")]
    public string UsrSpecialist { get; set; }
}

How would I go about pasting my custom field values from the Sales Order details to Shipment and AR Invoice?

1 answer

  • answered 2018-02-13 02:28 RuslanDev

    To paste custom field value from SOLine to SOShipLine, you should create an extension for the SOShipmentEntry BLC and override the CreateShipmentFromSchedules method as shown in the following sample below:

    public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
    {
        public delegate bool CreateShipmentFromSchedulesDel(
            PXResult<SOShipmentPlan, SOLineSplit, SOLine, InventoryItem, INLotSerClass, INSite, SOShipLine> res,
            SOShipLine newline, SOOrderType ordertype, string operation, DocumentList<SOShipment> list);
    
        [PXOverride]
        public bool CreateShipmentFromSchedules(
            PXResult<SOShipmentPlan, SOLineSplit, SOLine, InventoryItem, INLotSerClass, INSite, SOShipLine> res,
            SOShipLine newline, SOOrderType ordertype, string operation, DocumentList<SOShipment> list,
            CreateShipmentFromSchedulesDel del)
        {
            SOLine line = (SOLine)res;
            PXFieldDefaulting specialistFieldDefaulting = new PXFieldDefaulting((s, a) =>
            {
                if (line != null)
                {
                    a.NewValue = line.GetExtension<SOLineExt>().UsrSpecialist;
                    a.Cancel = true;
                }
            });
    
            bool result;
            Base.FieldDefaulting.AddHandler<SOShipLineExt.usrSpecialist>(specialistFieldDefaulting);
            try
            {
                result = del(res, newline, ordertype, operation, list);
            }
            finally
            {
                Base.FieldDefaulting.RemoveHandler<SOShipLineExt.usrSpecialist>(specialistFieldDefaulting);
            }
            return result;
        }
    }
    

    This is how a newly created Shipment should look like: enter image description here after execution of the Create Shipment action for the Sales Order below: enter image description here

    To paste custom field value to ARTran, you should create an extension for the SOInvoiceEntry BLC and override the CreateTranFromShipLine method.

    Because the Prepare Invoice button, found on both the Sales Orders (SO301000) and Shipments (SO302000) screens, can be used to create a new AR Invoice either based on Shipment details or straight from Sales Order details for those orders, which order type does not process shipments (the Process Shipments option is unchecked on the Order Types screen), it's necessary to verify if the current sales order's type process shipments or not. For Order Types, that process shipments, we will paste custom field value from SOShipLine to ARTran. Otherwise, custom field value will be pasted from SOLine to ARTran.

    public class SOInvoiceEntry_Extension : PXGraphExtension<PX.Objects.SO.SOInvoiceEntry>
    {
        public delegate ARTran CreateTranFromShipLineDel(ARInvoice newdoc, SOOrderType ordertype, string operation,
            SOLine orderline, ref SOShipLine shipline);
    
        [PXOverride]
        public ARTran CreateTranFromShipLine(ARInvoice newdoc, SOOrderType ordertype, string operation,
            SOLine orderline, ref SOShipLine shipline, CreateTranFromShipLineDel del)
        {
            var arTran = del(newdoc, ordertype, operation, orderline, ref shipline);
            PXCache<ARTran>.GetExtension<ARTranExt>(arTran).UsrSpecialist = ordertype.RequireShipping == true ?
                shipline.GetExtension<SOShipLineExt>().UsrSpecialist :
                orderline.GetExtension<SOLineExt>().UsrSpecialist;
            return arTran;
        }
    }
    

    Here is an example of a new AR Invoice: enter image description here prepared for the Shipment below: enter image description here

    And this is how a new AR Invoice should look like: enter image description here after execution of the Prepare Invoice action for a Sales Order of the Order Type, that does not process shipments: enter image description here

    For an example on how to paste custom field values from the AR Invoice details directly into GL Transactions, please check this answer.