Flow a custom field from posted payment journal to vendor/customer transaction in Dynamics 365 Finance and Operations.

Hello everyone,

Whenever you add a new custom field to a payment journal, so then it’s become very important to flow that field to the posted transaction tables as well when that journal gets posted.

So today I’ll show you how you can implement a logic to flow a custom field from posted payment journal to a vendor/customer transaction table in D365 F&O using extensions and COC pattern.

VENDOR TRANSACTION

  1. Add a field (xyzExpenseCode) to the extensions of the LedgerJournalTrans table and LedgerJournalTransVendPaym form.
  2. Now add a field (xyzExpenseCode) to the extensions of the VendTrans table and form.
  3. Create an extension of VendVoucher class (VendVoucherxyz_Extension) to wrap the initCustVendTrans method to define the following mapping between journal and vendor transaction fields.

protected void initCustVendTrans(
CustVendTrans _custVendTrans,
LedgerVoucher _ledgerPostingJournal,
boolean _useSubLedger)
{
next initCustVendTrans(_custVendTrans, _ledgerPostingJournal, _useSubLedger);
VendTrans vendTrans = _custVendTrans as VendTrans; // Get vendTrans table buffer form CustVendTrans map instance
If (common == ledgerJournalTrans )
{
LedgerJournalTrans ledgerJournalTrans = common; // Get journalLine table buffer
vendTrans.xyzExpenseCode = ledgerJournalTrans.xyzExpenseCode; // Define mapping for custom fields
}
}

CUSTOMER TRANSACTION

  1. Add a field (xyzExpenseCode) to the extensions of the LedgerJournalTrans table and LedgerJournalTransCustPaym form.
  2. Similarly, add a field (xyzExpenseCode) to the extensions of the CustTrans table and form.
  3. Lastly, create an extension of CustVoucher class (CustVoucherxyz_Extension) to wrap the initCustVendTrans method to define the following mapping between journal and customer transaction fields.

protected void initCustVendTrans(
CustVendTrans _custVendTrans,
LedgerVoucher _ledgerPostingJournal,
boolean _useSubLedger)
{
next initCustVendTrans(_custVendTrans, _ledgerPostingJournal, _useSubLedger);
CustTrans custTrans = _custVendTrans as CustTrans; // Get custTrans table buffer form CustVendTrans map instance
If (common == ledgerJournalTrans )
{
LedgerJournalTrans ledgerJournalTrans = common; // Get journalLine table buffer
custTrans.xyzExpenseCode = ledgerJournalTrans.xyzExpenseCode; // Define mapping for custom fields
}
}

Now when you post a payment journal, so along with all other fields your custom field will also move to the respective transaction tables.

Happy Daxing,

References:

https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/extensibility/method-wrapping-coc

How to add a new bank cheque format in Dynamics 365 Finance and Operations using extensions and handlers?

Hello everyone,

In this session, I’ll share my knowledge that how can we add a new cheque format in D365 F&O through extensions and handlers.

Mandatory Steps:

  • Open Visual studio and create a new Dynamics365 project.
  • Now, create a report (xyzCheque_US) to design it as per your requirement (you can also duplicate any existing cheque report and make the required changes like I did).
Design it as per requirement
  • Create a new output type Menu-item (xyzCheque_US) and set the following properties.
Menu-item
Menu-item properties
  • Create an extension of base enum CheckFormType (CheckFormType.xyzExtension) to add a new option (xyzUSStyle) for your cheque format.
Extended Enum

Cash and bank management > bank accounts > bank accounts > layout > Check > Check form
  • Now we need to create some classes to execute this newly created cheque format.

1.Create xyzBankChequePrintHandler class and add a following handler for a provided delegate.

[SubscribesTo(classStr(BankChequePrint), delegateStr(BankChequePrint, printDocumentDelegate))]
public static void determineReportMenuOutput(ChequeFormType _chequeFormType, EventHandlerResult _eventResult)
{
if (_chequeFormType == ChequeFormType::xyzUSStyle)
{
_eventResult.result(menuItemOutputStr(xyzCheque_US));
}
}

2. Create xyzChequeControllerHandler class and add a following handler.

[SubscribesTo(classStr(ChequeController), delegateStr(ChequeController, initChequeReportFromChequeFormTypeDelegate))]
public static void initChequeReportFromChequeFormType(ChequeFormType _chequeFormType, BankChequeLayout _bankChequeLayout, EventHandlerResult _eventResult)
{
if (_chequeFormType == ChequeFormType:: xyzUSStyle)
{
_eventResult.result(ssrsReportStr(xyzCheque_US, Report));
}
}

3. Create xyzCustVendChequeTxtCalHandler class and add a following handler.

[SubscribesTo(classStr(CustVendChequeSlipTextCalculator), delegateStr(CustVendChequeSlipTextCalculator, getChequeDocLengthDelegate))]
public static void getChequeDocLength(ChequeFormType _chequeFormType, EventHandlerResult _eventResult)
{
const real ChequeSizeDefault = 88.89; // define as per your requirement
if (_chequeFormType == ChequeFormType::xyzUSStyle)
{
_eventResult.result(ChequeSizeDefault);
}
}

4. Create an extension class BankPrintTestChequexyz_Extension of BankPrintTestCheque class and add the following two methods (here we will be using COC pattern to execute our logic).

protected boolean canRunChequePrintForExtendedFormType(TmpChequePrintout _tmpChequePrintout)
{
boolean isExtended = next canRunChequePrintForExtendedFormType(_tmpChequePrintout);
isExtended = _tmpChequePrintout.ChequeFormType == ChequeFormType::xyzUSStyle;
return isExtended;
}

protected void runChequePrintForExtendedChequeFormType(TmpChequePrintout _tmpChequePrintout)
{
next runChequePrintForExtendedChequeFormType(_tmpChequePrintout);
if (_tmpChequePrintout.ChequeFormType == ChequeFormType::xyzUSStyle)
{
Args args = this.getChequePrintArgs(_tmpChequePrintout);
new MenuFunction(menuitemOutputStr(xyzCheque_US), MenuItemType::Output).run(args);
}
}

Recommended Steps:

Although below steps are optional but these are recommended to avoid BP errors and to follow best practices.

  • Create a new Privilege (xyzBankChequeGenerate) and drag your menu-item (xyzCheque_US) to its Entry points to set the required security for this menu-item.
  • Create an Extensions of PaymVendorPaymentsMaintain and BankBankTransactionsMaintain duties and add new privilege (xyzBankChequeGenerate) to these existing duties.

Now, deploy your report, run your project and test this newly created cheque format by following this link.

Thanks and have a nice day.

References: