Local Macros and Regular Expressions in Dynamics AX 2012

by | Updated August 15, 2016 | Development, Dynamics AX

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

  • The Safari browser is now supported natively on Dynamics AX 2012 R2 as well as being supported on Dynamics AX RTM with a hotfix.  Taken from the updated System Requirements…

  • I put together some certification information on the requirements for Microsoft Dynamics AX 2012 and a proposed training roadmap to get to each of the core certifications.  Rather than have this…

  • With the announcement of the release of Microsoft Dynamics AX 2012 R2, Microsoft released an updated system requirements document for AX 2012: http://www.microsoft.com/en-us/download/details.aspx?id=11094.  Windows 2012 Server is now supported, but…


Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events


06oct10:00 am10:30 amPreview of D365 Business Central Fall Release Features and Functionality

06oct12:00 pm12:30 pmInsider's Guide to New Features Available in the Fall Release of D365 Finance and Supply Chain

07oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Technical

13oct12:00 pm12:30 pmWave 2 Release – What’s Coming for Dynamics 365 Sales and Customer Service

21oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Functional

26oct(oct 26)9:00 am28(oct 28)5:00 pmStoneridge Connect Leadership and Community Conference


04nov11:00 am12:00 pmConfab LIVE with Stoneridge - Challenging the Development Paradigm

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!