Posts

Showing posts from March, 2018

Reading XML using X++

In X++ there are some tools available to read an incoming XML file and do some work with it.  XMLNode, XMLNodeList, and XMLElement are the main ones.  An example below shows using a for loop to move through tags under a root.  You can then nest for loops in order to go through more complex XML files. nodeRoot = _xmlDoc.getNamedElement('ROOT'); nodeList = nodeRoot.childNodes();         for (i=0; i < nodeList.length(); i++)         {             node = nodeList.item(i);             switch(node.name())             {                 case 'NODE1':                       //Insert your code here                       break;                 case 'NODE2...

Using X++ to get a list of files in a directory

If you have the need to read a specific directory to get a list of files from it, the following code uses System.IO objects which will work in batch if needed. static container findMatchingFiles(         str _folderPath,         str _filePattern   = '*.*') {     System.IO.DirectoryInfo     directory;     System.IO.FileInfo[]        files;     System.IO.FileInfo          file;     InteropPermission           permission;     str                         fileName;     counter                     filesCount;     counter                     loop;     container        ...

Working with TextIO Codepage

Many X++ developers will have used the TextIO class to write files at some point.  Generally we will use it as such: MyTextIO = new TextIO(MyFile, #IO_Write); There is an optional 3rd parameter to the new method of the TextIO class, and this is the codepage of the output file.  The actual definition of the new method from MSDN: public void new( str filename, str mode, [int codepage]) The default setting for codepage is UTF-16LE, which is fine if you are exporting CSV data to be opened in Excel, for example.  But in the world of ERP systems, many interfaces are with older technology, and while you can't spot the difference just using something like Notepad, looking at the output file in a hex editor would of course show the difference between the default codepage and a simpler one.  Certain interfaces, for example outputting payment or check information to a bank, will require a codepage such as 0 for ANSI.  The MSDN entry (link below) has th...