Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 58670

AOT Find tool – old but useful

$
0
0

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

/*
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.
*/


Viewing all articles
Browse latest Browse all 58670

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>