Every financial transaction in Dynamics AX can (and
normally should) have a descriptive transaction text. Some texts are
entered by user, some are generated by the system. The latter option
happens for automatically generated transactions where the user cannot
interact with the process.
Dynamics AX provides a way to define texts for automatically generated transactions. The setup can be found in Basic | Setup | Transaction text.
Here the user can create custom transaction texts for various automatic
transaction types and languages. The text itself can have a number of
placeholders digits with percent sign in front of them, which are
replaced with actual values during the process. Placeholders can be from %1 to %6 and they are replaced with the following values:
%1: the transaction date
%2: a relevant number like invoice, delivery note, etc.
%3: the voucher number
%4-%6: custom; depends on the module
Although most of the time
the existing values are enough, I was still requested a number of times
to add additional ones. One of the latest requests was to include the
vendor name into vendor payment journal lines automatically generated by
payment proposals. We will use this case as an example in this recipe.
Getting ready
First we need to make sure the vendor payment transaction text is set up properly. Open Basic | Setup | Transaction text, find a line with Vendor - Payment, Vendor and change the text to Payment to %5 like the following:
How to do it...
1. Open AOT, find the CustVendPaymProposalTransferToJournal class and add the following code to its getTransactionText():
transactionTxt.setKey2(
_custVendPaymProposalLine.custVendTable().Name);
right after:
transactionTxt = new TransactionTxt(
LedgerTransTxt::VendPaymentVend);
2. Open Accounts payable | Journals | Payments | Payment journal and create a new journal. Then create payment lines using the Create payment proposal function. Notice that now the transaction texts include vendor name:
How it works...
The lines generated by vendor payment proposals are transferred into the journal by using the CustVendPaymProposalTransferToJournal class. Its getTransactionText() method is responsible for formatting transaction texts. If we look inside it we can see that the TransactionTxt class is used for this purpose. The following methods are used for each placeholder:
%1: setDate()
%2: setFormLetter()
%3: setVoucher()
%4: setKey1()
%5: setKey2()
%6: setKey3()
By looking at the code we can see that only %4 (setKey1()) is used, so we can occupy %5 and fill it with the vendor name. To achieve that, we have to call setKey2() with the vendor name as an argument. We place the code in the ModuleCustVend::Vend section of the switch statement to make sure it is executed only when generating vendor payments.
There's more...
If more than 3 custom placeholders are required it is always possible to add an additional one by creating a new setKey() method in the TransactionTxt class. For example, if we want to add placeholder %7 we have to do the following:
Add the following code to the class declaration:
Create a new method:
void setKey4(str 20 _key4)
{;
key4 = _key4;
}
Change the last line of the txt() method to:
return strfmt(
txt,
transDate,
formLetterNum,
voucherNum,
key1,
key2,
key3,
key4);
After those modifications we can use setKey4() when generating transactions.
Although even more
placeholders could be added, it should be considered that the
transaction text field has a finite number of characters and excessive
text will be simply truncated.