Local Macros and Regular Expressions in Dynamics AX 2012

By Ramesh Singh | March 9, 2016

I was recently working on a customer project where I wanted to use regular expressions to do string comparison in Dynamics AX 2012. The customer wanted to identify the type of card and validate the card from the card number, based on the range of card numbers assigned to the card issuer. We can use regular expression to compare the card number with major providers and derive the type of card and validity of the card number.

Shortcomings in the #define Command

X++ provides several pre-compiler directives that we can use. The directives are processed before the resulting X++ code is given to the X++ compiler. These directives declare and handle macros and their values.

I decided to use the #define command, to store the constant value for regular expression for various card issuers in a macro. I ran into an existing shortcoming in the #define command. When we have closing brackets ‘)‘ in a macro value, Dynamics AX gives a compiler error with the description ‘Syntax error.’

Syntax Error in Dynamics AX

Compiler Output Error in Dynamics AX

The workaround for this is to use localMacro instead.

 Local Macro in Dynamics AX

 

How to use Regular Expression in Dynamics AX

A regular expression is a pattern that the regular expression engine attempts to match in input text. Dynamics AX also provides extensive support for regular expression. Using Regular Expression in Dynamics AX is very simple, due to the ability to call .NET objects from AX.

Regular Expression in Dynamics AX

Happy coding!

Related Posts


Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!