Posts

Showing posts with the label AX development

SysCompareText class – text comparison with white spaces.

Text comparison in Dynamics AX is very easy and is provided by the == operator and the strcmp() method. The difference between these two is that == is case insensitive whereas strcmp() is case sensitive. Let us suppose we have a case where we need to compare two strings Text1=’A new string’; Text2=’A new string’; Now logically these two strings are same semantically if not for the extra white spaces. So how can we compare them? This is where the SysCompareText class can be helpful. The static run() method takes a parameter _suppressWhiteSpaces which can control if white spaces within string should be taken into account while comparing strings. A value of true which by the way is the default value for this will ensure that white spaces are not considered while comparing. So text1 & Text2 are shown as identical. A value of false will show that Text1 & Text2 in the above case are not equal. You can download the code for this from here .

Create() method in the AX foundation classes.

Image
When it comes to creating and using Maps, Lists or Arrays, we normally initialize them using the new() method. Then we use the respective methods on these to insert the data. All these classes have a static method create() which can both initialize and insert values into these at the same time. Even though, the method takes a container parameter in all the three cases, the content of the containers are very different from each other. Let us look at all the three in detail. Download the XPO for the source code from here . Code for Array class. static void ArrayInit(Args _args) { Array ageArray, nameArray; container conValues; counter i; ; conValues = [1, 1, 3, 10, 20, 30, 40]; ageArray = Array::create(conValues); print "Printing age array (consecutive values) ..."; for(i=1; i { print ageArray.value(i); } conValues = [2, 1, 3, 2, 20, 4, 40]; ageArray = Array::create(conValues); print...