page contents

AOT Find tool – old but useful


I was looking for a certain pattern in the code, using the AOT Find-tool.
There is an option to use “Filter”, which will then run a validation function like :

boolean filterMethod(str _treeNodeName, str _treeNodeSource, XRefPath _path, ClassRunMode _runMode) { %1 }

where the %1 will be replaced with your filter text to form a complete validation function.

If this validation function returns “true”, the AOT node of the search context will appear in the search results.
Here you can write X++ code and use i.e. regular expressions,
like:

//looking for "if" statements in the "while select" loops
str matchPattern = '.+while select.*if.+';

System.Text.RegularExpressions.Match myMatch;
str s;

// Check if we have the treeNode source
if(!_treeNodeSource)
return false;

// RegEx does not works properly over multiple lines, we remove the CR, LF here to get rid of it
s = strReplace(_treeNodeSource, "\r\n", "");
s = strReplace(s, "\r", "");
s = strReplace(s, "\n", "");

// Perform the match
myMatch = System.Text.RegularExpressions.Regex::Match(s, matchPattern);

// Return the match result
return(myMatch.get_Success());

In AX 2012, there is also a possibility to use the match function instead,
like:

//looking for "if" statements in the "while select" loops
str matchPattern = '.+while select.*if.+';

str s;
int matchResult;

// RegEx does not works properly over multiple lines, we remove the CR, LF here to get rid of it
s = strReplace(_treeNodeSource, "\r\n", "");
s = strReplace(s, "\r", "");
s = strReplace(s, "\n", "");

// 1 if the pattern is located in the string; otherwise, 0
matchResult = match(matchPattern, s);

// Return the match result
return (matchResult == 1);

Now time to try this out on my test class:

aot-find-tool-002

and I get the results sweetly listed there in the search results:

aot-find-tool-003
For more information on Regular expressions syntax,
You might use https://msdn.microsoft.com/en-us/library/cc295435.aspx

Update 13/04/2016 – Related topic: How to: Search Application Object Properties [AX 2012]

/*
DISCLAIMER:
Microsoft provides programming examples for illustration only,
without warranty either expressed or implied, including, but not limited to,
the implied warranties of merchantability or fitness for a particular purpose.

This post assumes that you are familiar with the programming language that is being demonstrated
and the tools that are used to create and debug procedures.
*/

Comments (2)
  1. Denis says:

    Is it possible in AX7? there is a metadata search tool but I think you can’t do this in it

    1. mehrg says:

      One of the suggested approaches would be using “Metadata search in Visual Studio” (see https://ax.help.dynamics.com/en/wiki/metadata-search-in-visual-studio/).

Comments are closed.

Skip to main content