Tuesday, September 23, 2025

Update custom fields in voucher transactions in D365F&O X++

The code below will work for voucher transactions that were created automatically.

[ExtensionOf(classStr(LedgerVoucherTransObject))]

internal final class Dax_LedgerVoucherObject_Extension

{

   public void initFromLedgerPostingTransaction(

       LedgerPostingTransactionTmp _ledgerPostingTransaction,

       LedgerPostingTransactionProjectTmp _projectPostingTransaction)

   {

       next initFromLedgerPostingTransaction(_ledgerPostingTransaction,_projectPostingTransaction);

 

       generalJournalAccountEntry.Dax_CosnsolidateAccount = "testloc"; //Custom field

   }

}

The code below will work for voucher transactions that are transferred manually or through a batch.

[ExtensionOf(classStr(SubledgerJournalTransferCommand))]

internal final class Dax_SubledgerJournalTransferCommand_Extension

{

   public void executeTransfer(SubledgerJournalTransferRequest subledgerJournalTransferRequest)

   {

       GeneralJournalAccountEntry          accountEntry;

       GeneralJournalEntry                 generalJournalEntryloc;

       SubledgerJournalEntry subledgerJournalEntry;

       next executeTransfer(subledgerJournalTransferRequest);

       select subledgerJournalEntry

          where subledgerJournalEntry.RecId == transferidVal;

       if(subledgerJournalEntry.Status == SubledgerJournalEntryStatus::Transferred)

       {

           select generalJournalEntryloc

              where generalJournalEntryloc.TransferId ==subledgerJournalEntry.TransferId;

           while select forupdate accountEntry

              where accountEntry.GeneralJournalEntry == generalJournalEntryloc.RecId

           {

               ttsbegin;

               accountEntry.Dax_CosnsolidateAccount = "test"; //Custom field

               accountEntry.update();

               ttscommit;

           }

       }

   }

}

...............

Output :

The above code works for voucher transactions that were created in the following ways :

1.Scenario - Product receipt voucher transactions. Manually transfer


2.Vendor invoice journal


3.Vendor payment journal.
4.Sales Packing slip vouchers.
5.Sales order invoice vouchers.
6.Free text invoices.
7.General journals.
8.Movement journals.
9.Hour journals.
10.Expense journals
11.Fixed asset journals. etc..




 





Saturday, September 20, 2025

Generate URL link to a particular form and record

 

using Microsoft.Dynamics.AX.Framework.Utilities;

internal final class Dax_GenerateURLForRecord

{

   private static str buildAXURL(MenuItemName _menuItemName, MenuItemType _menuItemtype, DataSourceName _dataSource='', FieldName _field='', str _value='' )

   {

 

       UrlHelper.UrlGenerator generator = new UrlHelper.UrlGenerator();

 

       System.Uri currentHost = new System.Uri(UrlUtility::getUrl());

 

       generator.HostUrl = currentHost.GetLeftPart(System.UriPartial::Authority);

 

       generator.Company = "USMF";

       generator.MenuItemName = _menuItemName;

       generator.MenuItemType = _menuItemtype;

       generator.Partition = getCurrentPartition();

       generator.EncryptRequestQuery = true;

 

 

       if(_dataSource != '')

       {

           UrlHelper.RequestQueryParameterCollection requestQueryParameterCollection;

 

           requestQueryParameterCollection = generator.RequestQueryParameterCollection;

           requestQueryParameterCollection.UpdateOrAddEntry(_dataSource, _field, _value);

 

       }

       System.Uri fullURI = generator.GenerateFullUrl();

       return fullURI.AbsoluteUri;

   }

 

   public static void main(Args _args)

   {

       str link; 

       link = Dax_GenerateURLForRecord::buildAXURL(menuItemDisplayStr(PurchTableListPage), MenuItemType::Display, formDataSourceStr(PurchTable,PurchTable), fieldstr(PurchTable, PurchId), "000039" );

 

       info(link);

   } 

}

...........................