Wednesday, August 7, 2024

How to Copy Custom Fields Throughout the Purchase Order Process in D365 F&O Using X++

 A new custom field has been added to the Purchase Order (PO) header in Dynamics 365 Finance & Operations. This field must be automatically carried forward throughout the entire procurement lifecycle to ensure visibility and consistency across related documents and journal records. Specifically, the custom field should be copied to the following procurement artifacts:

  • Purchase Order Confirmation

  • Purchase Order Confirmation Journals

  • Product Receipt

  • Product Receipt Journals

  • Purchase Invoice

  • Purchase Invoice Journals


Purchase Order Header :




Purchase Order Confirmation & Product Receipt

[ExtensionOf(classStr(PurchFormletterParmData))]

internal final class DaxPurchFormLetterParmData_Extension

{

   protected VendDocumentTableMap initializeParmTable(

     VendDocumentTableMap  _parmTable,

     PurchLine             _purchLine,

     PurchTable            _purchTable,

     TradeLineRefId        _tableRefId,

     boolean               _hold,

     boolean               _notApproved ,

     Num                   _purchSummaryFormLetterId,

     VendPostingProfile    _postingProfile ,

     InventProfileType_RU  _inventProfileType)

   {

       VendDocumentTableMap map = next initializeParmTable(_parmTable,

                                                        _purchLine,

                                                        _purchTable,

                                                         _tableRefId,

                                                         _hold,

                                                         _notApproved ,

                                                         _purchSummaryFormLetterId,

                                                         _postingProfile ,

                                                        _inventProfileType);

  

       if(this.parmDocumentStatus() != DocumentStatus::Invoice)

       {

           PurchParmTable  purchParmTable  = _parmTable;

           purchParmTable.DaxComment = _purchTable.DaxComment;

       }    

       return map;

   }

}





Purchase Order Confirmation Journals

[ExtensionOf(classStr(PurchPurchOrderJournalcreate))]

internal final class DaxPurchPurchOrderJournalcreate_Extension

{

   /// <summary>

   /// Initializes the journal header record.

   /// </summary>

   protected void initJournalHeader()

   {

       next initJournalHeader();

       vendPurchOrderJour.DaxComment = purchParmTable.DaxComment;

   }

}

field is modified and confirmed.



Product Receipt Journals 

[ExtensionOf(Classstr(PurchPackingSlipJournalCreate))]

internal final class DaxPurchPackingSlipJournalCreate_Extension

{

   /// <summary>

   /// Initializes non-correctable fields on the journal header.

   /// </summary>

   public void initHeader()

   {

       next initHeader();

       vendPackingSlipJour.DaxComment = purchParmTable.DaxComment;

   }

}

Custom field is modified and product receipt is posted.



Purchase Invoice

[ExtensionOf(classStr(PurchFormletterParmDataInvoice))]

internal final class DaxPurchFormLetterParmDataInvoice_Extension

{

   protected void insertParmTable(Common _vendInvoiceInfoTable)

   {

       VendInvoiceInfoTable  vendInvoiceInfoTable = _vendInvoiceInfoTable;

       PurchTable            purchTable;

 

       select purchTable

           where purchTable.PurchId == vendInvoiceInfoTable.PurchId;

 

       vendInvoiceInfoTable.DaxComment = purchTable.DaxComment;

       _vendInvoiceInfoTable = vendInvoiceInfoTable;

 

       next insertParmTable(_vendInvoiceInfoTable);   

   }

}



Purchase Invoice Journals

[ExtensionOf(classStr(PurchInvoiceJournalCreate))]

internal final class DaxPurchInvoiceJournalCreate_Extension

{

   protected void initJournalHeader()

   {

       next initJournalHeader();

       vendInvoiceJour.DaxComment = vendInvoiceInfoTable.DaxComment;

   }

}

Field is modified to "Test invoice" and invoice is posted.