Monday, October 26, 2020

Mandatory Affixes as per AppSourceCop Rule AS0011 in Microsoft Dynamics Business Central

 Hi All, 

I hope you'll are doing well. 

Business Central 17 has come up with a lot of improvements and functionalities, and one of them is Mandatory Affixes which is very important for developers w.r.t Code Standardization and managing their objects.

AppSourceCop Rule AS0011: An affix is required

Now, what does that mean! Let's look into it in detail. 

In order to avoid name clashes for objects added by your extension and objects added by other extensions, an affix must be prepended or appended to the name of all new application objects, extension objects, and fields. That is a suffix or a prefix is required. 

This can be done by using the property mandatoryAffixes in AppSourceCop.json. 

Change: The mandatory prefix and mandatory suffix properties are now both defining an affix that can be used either as prefix or as suffix.

The mandatoryAffixes property expects to receive an array of string as follows

{

    "mandatoryAffixes": [ "Test", "Case", "New" ]

}

Example:

If the existing codeunit doesn't contain an affix, it should be modified as follows:

Note: Applicable to all objects

Existing Codeunit:

codeunit 50100 ExistingCodeunit

{

    procedure MyProcedure()

    begin

        // Business logic.

    end;

}

Modified Extension Codeunit:

codeunit 50100 MyCodeunit

{

    ObsoleteState = Pending;

    ObsoleteReason = 'Use Test_MyCodeunit instead.'; 

    procedure MyProcedure()

    var 

        c: Codeunit Test_MyCodeunit;

    begin

        // Re-direct calls to not break the runtime behaviour of dependent extensions.

        c.MyProcedure();

    end;

}

//using one of the affixes mentioned in the mndatoryAffixes array

codeunit 50120 Test_MyCodeunit

{

    procedure MyProcedure()

    begin

        // Business logic.

    end;

}

Check more rules here: AppSourceCop Analyzer Rules


Hope this blog was helpful. See you until next time. :) 

Check out other blogs, if you haven't already. 

Please suggest what else do you want me to blog about. Keep following and supporting!

You can also email me at jyotsnaoberainav@gmail.com

Also, visit my website JONAV if you are looking for NAV/D365BC Training and/or Services!

Thank you! 


1 comment:

  1. This comment has been removed by the author.

    ReplyDelete