Wednesday, 28 February 2018

Read text files that have line feed (LF) using X++

Here is an intrusting scenario, There was a task to read a csv file and do some xyz task. As we all developers know, it will work fine in Dev and when it comes to UAT, the actual scenario will come out.
The issue was, the file which they provided is with only Line Feed (LF) and hence it looks like below when opened in notepad.

we can see the line feed in the Notepad ++  as below.
As usual, the code did not work.  To fix this issue, I have added the below code

inputFile = new TextIo(@"c:\temp\Input.csv", 'R');
inputFile .inFieldDelimiter(',');
inputFile .inRecordDelimiter("\n");

which done the trick.

Note: If you have both line feed (LF) and carriage return (CR)
we can use inputFile .inRecordDelimiter("\r \n");



Removing Line Feed and Carriage Return from Strings

costCenter = strReplace(conPeek(_lineContainer, 17), '\n','');
 costCenter = strReplace(costCenter, '\r','');

No comments:

D365FO : Script for update Storage Dimension Group for the Items with no transactions. x++

We have a problem on finance test... The storage dimension group = Mlok is setup to use warehouse management. But we don't have all the ...