D365 FO Customization Archives - Impulz Technologies LLC https://impulztech.com/tag/d365-fo-customization/ Microsoft Dynamics and Power Platform consulting company Tue, 18 Oct 2022 14:53:19 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 https://impulztech.com/wp-content/uploads/2022/08/cropped-impulz-tech-32x32.png D365 FO Customization Archives - Impulz Technologies LLC https://impulztech.com/tag/d365-fo-customization/ 32 32 Microsoft Dynamics 365 Finance and Operations: Customization of non-extendable code https://impulztech.com/microsoft-dynamics-365-finance-and-operations-customization-of-non-extendable-code/ Tue, 18 Oct 2022 14:53:19 +0000 https://impulztech.com/?p=2736 In Dynamics 365 Finance and Operations customization in standard objects is done through extension-based development. But there are some scenarios where a class method which needs to be customized through CoC (Chain of Command) is having Hookable attribute set as False. In that case you cannot create a CoC of that method. For example, there […]

The post Microsoft Dynamics 365 Finance and Operations: Customization of non-extendable code appeared first on Impulz Technologies LLC.

]]>

In Dynamics 365 Finance and Operations customization in standard objects is done through extension-based development. But there are some scenarios where a class method which needs to be customized through CoC (Chain of Command) is having Hookable attribute set as False. In that case you cannot create a CoC of that method.

For example, there is a class with a run method’s Hookable property set as false.

Public class CredManCreditLimitAdjGenerate extends RunBase
{
    [Hookable(false)]
    public void run()
    {
        if (!this.validate())
        {
            throw error("@SYS18447");
        }
    if (deleteExistingLines && CredManCreditLimitAdjTrans::exist(journalId))
        {
            CredManCreditLimitAdjTrans::deleteAllJournalLines(journalId);
        }
    this.processQueryRun();
    }
}

In this scenario the requirement is to execute some logic after this class’s run method execution is done. If it was a Hookable[true] method then you can simply create an extension of the class CredManCreditLimitAdjGenerate, create a CoC of run() and perform your new logic after the next call of run method. But in this case, you cannot do so.

In order to achieve this requirement technically you just create a new class CredManCreditLimitAdjGenerate_Impulz and set it as a child of CredManCreditLimitAdjGenerate class. Then override run() and include all the parent code with your required logic in it. Below is the code:

Public class CredManCreditLimitAdjGenerate_Impulz extends CredManCreditLimitAdjGenerate
{
    [Hookable(false)]
    public void run()
    {
        if (!this.validate())
        {
            throw error("@SYS18447");
        }
        if (deleteExistingLines && CredManCreditLimitAdjTrans::exist(journalId))
        {
            CredManCreditLimitAdjTrans::deleteAllJournalLines(journalId);
        }
        this.processQueryRun();

        //Write your required new logic here
    }
}

The additional thing you have to do is to change the reference of the original class to your new class by initializing its object or if the class is called from a menu item/button, then simply hide the menu item/button and add a new one with you new class reference.

Using the above approach you can also completely remove the standard run method logic and just add new logic which cannot be possible in case of CoC as you do have to call next() before or after new logic unless the method has the attribute Replaceable[true]. Replaceable[True] allows to skip next call in the extended method.

Note: If the class is private or internal or final then it cannot be extended so in that case you have to entirely copy the class with new name and change the reference in code.

The post Microsoft Dynamics 365 Finance and Operations: Customization of non-extendable code appeared first on Impulz Technologies LLC.

]]>