Tuesday 22 May 2018

Macros & Const in AX7 / D365

Macros can still be created in Dynamics 365 for Finance and Operations to store a value that will not be modified.  They are created in either a macro file or by using the pound define keyword.  So we can see that here with our either hash tag or pound define.  

However, there is a new modifier to create constant variables.  By placing the keyword const before a variable, it will create the value that cannot be modified.

Const allows you to define members on a class and variables in a method that can only be initialized during the declaration. Constant value must be known at compile time. Compiler will replace references to these constants with the literal value.

Const also replaces most use cases of macros.

Example code:

Key Benefits:
IntelliSense in the editor.
- Support for "Go to definition" in the editor.
- Full control of the type for the constant.
- Faster compilation – macros are notorious hard for the compiler to handle.
- None of the macro idiosyncrasies – like the ability to redefine/override.

Reference link: X++ in AX7: Const keyword

No comments:

Post a Comment

How to Get Customer Free Text Invoice "Totals" form field value with X++ in D365FO

Customer free text invoices are an essential aspect of financial management in D365FO. In this blog, I have compiled all the code needed to ...