Skip to main content
Solved

Copy Custom Field Values from Shipment Line to Invoice Line and Copy Custom Field Values from Purchase Order Header to Purchase Receipt Header


Forum|alt.badge.img+2

Hi I have 2 requirements,

  1. Copy Custom Field Values from Shipment Line to Invoice Line (SOShipLine → ARTran)
  2. Copy Custom Field Values from Purchase Order Header to Purchase Receipt Header (POOrder → POReceipt) 

How can I implement this? 

Is there a way I can use PXOverride and update the fields on invoice line creation and purchase receipt creation.

For example this is an implementation I did for copying field values from sales order header to shipment header screen.

public delegate void CreateShipmentDelegate(CreateShipmentArgs args);

        [PXOverride]
        public void CreateShipment(CreateShipmentArgs args, CreateShipmentDelegate baseMethod)
        {
            // Call the original method to ensure default behavior
            baseMethod(args);

            // Retrieve the current shipment and order
            SOShipment ship = Base.Document.Current;
            SOOrder order = args.Order;

            if (ship != null && order != null)
            {
                // Use the extension cache to access the custom fields
                SOShipmentExt shipExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(ship);
                SOOrderExt orderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(order);

                // Update custom fields in the shipment header
                shipExt.UsrCommission = orderExt.UsrCommission;
                shipExt.UsrCustomerPickUp = orderExt.UsrCustomerPickUp;
                shipExt.UsrDuty = orderExt.UsrDuty;
                shipExt.UsrFreight = orderExt.UsrFreight;
                shipExt.UsrInsurance = orderExt.UsrInsurance;
                shipExt.UsrQtyShow = orderExt.UsrQtyShow;
                shipExt.UsrQtyNote = orderExt.UsrQtyNote;
                shipExt.UsrShippingTermsINCOTERM = orderExt.UsrShippingTermsINCOTERM;
                shipExt.UsrCurrencyTerms = orderExt.UsrCurrencyTerms;

                // Update and save the shipment header
                Base.Document.Update(ship);
                Base.Save.Press();            
            }
        }

 

Thank you!

Best answer by Naveen Boga

@TharidhiP  Please use the below code to COPY the value from SOShipLine to ARTran and same way you try for other requirement as well.

 

  #region UsrAdditionalBox
  [PXDBBool]
  [PXUIField(DisplayName = "Test Box")]
  [PXDefault(typeof(Search<SOShipLineExt.usrAdditionalBox,
                        Where<SOShipLine.shipmentType, Equal<Current<ARTran.sOShipmentType>>,
                        And<SOShipLine.shipmentNbr, Equal<Current<ARTran.sOShipmentNbr>>,
                        And<SOShipLine.lineNbr, Equal<Current<ARTran.sOShipmentLineNbr>>>>>>),
                        PersistingCheck = PXPersistingCheck.Nothing)]

  public virtual bool? UsrAdditionalBox { get; set; }
  public abstract class usrAdditionalBox : PX.Data.BQL.BqlBool.Field<usrAdditionalBox> { }
  #endregion

 

View original
Did this topic help you find an answer to your question?

3 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3404 replies
  • Answer
  • August 29, 2024

@TharidhiP  Please use the below code to COPY the value from SOShipLine to ARTran and same way you try for other requirement as well.

 

  #region UsrAdditionalBox
  [PXDBBool]
  [PXUIField(DisplayName = "Test Box")]
  [PXDefault(typeof(Search<SOShipLineExt.usrAdditionalBox,
                        Where<SOShipLine.shipmentType, Equal<Current<ARTran.sOShipmentType>>,
                        And<SOShipLine.shipmentNbr, Equal<Current<ARTran.sOShipmentNbr>>,
                        And<SOShipLine.lineNbr, Equal<Current<ARTran.sOShipmentLineNbr>>>>>>),
                        PersistingCheck = PXPersistingCheck.Nothing)]

  public virtual bool? UsrAdditionalBox { get; set; }
  public abstract class usrAdditionalBox : PX.Data.BQL.BqlBool.Field<usrAdditionalBox> { }
  #endregion

 


Forum|alt.badge.img+8
  • Captain II
  • 366 replies
  • August 30, 2024

Hi @TharidhiP 

 

You could use a RowInserted Handler like so:

protected virtual void _(Events.RowInserted<POReceiptLine> e, PXRowInserted b)
{
POReceiptLine row = e.Row; //find current record
if(row == null) return;

POLine line = SelectFrom<POOrder>.Where<POLine.orderNbr.IsEqual<P.AsString>.And<POLine.orderType.IsEqual<P.AsString>>>.View.Select(base, row.PONbr, row.POType); // find related record in POLine table
if(order == null) return;

POReceiptLineExt rowExt = row.GetExtension<POReceiptLineExt>(row); //Get DAC Extension for POReceiptLine
POLineExt lineExt = line.GetExtension<POLineExt>(line); //Get DAC Extension for POLine


 rowExt.UsrCustomField1 = lineExt.UsrCustomField1 //Set POReceipLine value.

}

 


Forum|alt.badge.img+2
  • Author
  • Pro I
  • 103 replies
  • September 19, 2024

Thanks @Naveen Boga and @aiwan for the suggestions!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings