Skip to main content

Posts

Showing posts with the label read

How to read a CSV , txt file in AX 2009

1. First of all, make sure that the file is accessible and has sufficient permissions to read the file. 2. Now follow the below code which reads the file, reads all the lines in the file and inserts into the table. #File CommaIo aSCIIFile; Container recordsCon; FileIoPermission               perm; StudentTable                    studentTable; #define.ExampleFile(@"c:\test.txt") ; perm = new FileIoPermission(#ExampleFile, #io_read ); if (perm == null) { return; } // Grants permission to execute the CommaIo.new method. // CommaIo.new runs under code access security. perm.assert(); // BP deviation documented. aSCIIFile = new CommaIo( #ExampleFile ,#io_read); ttsbegin; while (aSCIIFile.status()== IO_Status::Ok) //Reading the ASCII file if records are there ...

X++ CODE TO READ MS OFFICE WORD DOCUMENT

Use the below job if you want to read text from MS Word document in Dynamics Ax 2009. static void FileIO_ReadFromWord(Args _args) { str document = "D:\\Demo Edition.doc"; COM wordApplication; COM wordDocuments; COM wordDoc; COM range; TextBuffer txt = new TextBuffer(); ; // Create instance of Word application wordApplication = new COM("Word.Application"); // Get documents property wordDocuments = wordApplication.Documents(); // Add document that you want to read wordDoc = wordDocuments.add(document); range = wordDoc.range(); txt.setText(range.text()); // to replace carriage return with newline char txt.replace('\r', '\n'); info(txt.getText()) ; }

Dynamics AX - code to Read/Write data to excel

Writing Data to Excel file How it works 1. Use SysExcelApplication class to create excel file. 2. Use SysExcelWorkbooks and SysExcelWorkbook to create a blank workbook(by default 3 worksheets will be available). 3. Use SysExcelWorkSheets to select worksheet for writing data. 4. SysExcelCells to select the cells in the excel for writing the data. 5. SysExcelCell to write the data in the selected cells. 6. Once you done with write operation use SysExcelApplication.visible to open file. static void Write2ExcelFile(Args _args) { InventTable inventTable; SysExcelApplication application; SysExcelWorkbooks workbooks; SysExcelWorkbook workbook; SysExcelWorksheets worksheets; SysExcelWorksheet worksheet; SysExcelCells cells; SysExcelCell cell; int row; ; application = SysExcelApplication::construct(); workbooks = application.workbooks(); workbook = workbooks.add(); worksheets = workbook.worksheets(); worksheet = worksheets.itemFromNum(1); cells = worksheet.cells(); cells.range('A:A').nu...

Read and alter registry settings in Axapta

Here is a sample code of increasing max. open cursors during run-time. But, please note that its purpose is only to show you how to read and write registry. If you encounter any open cursors problem, it is recommended to optimize the SQL statement rather than changing the setting for maximum open cursors. static void IncreaseMaxOpenCursors(Args _args) { #winapi container regRet; int readReg; int writeReg; str keyValue, keyPath, configName; int maxOpenCursors; ; //Specify your Axapta configuration utility name here configName = " LocalMachine "; //New maximum open cursor, default is 90 maxOpenCursors = 120; keyPath = @"SOFTWARENavisionAxapta3.0" + configName; readReg = WinAPI:: regOpenKey ( #HKEY_CURRENT_USER , keyPath, #KEY_READ ); if (readReg) { regRet = WinAPI::regGetValue(readReg, ‘opencursors’); keyValue = conpeek(regRet,1); info(keyValue); if (str2int(keyValue) < maxOpenCursors) { writeReg = WinAPI:...

How to read data from text (.txt) file with Ascii

It returns a container with the data in each line in the text file. That could be useful if you are reading a CSV file. In the following example I convert the container into text string and print it as an info message, line after line: void method1() { AsciiIo readFile; str line; container fileRecord; ; readFile = new AsciiIo("C:\\test.txt" , 'R'); readFile.inFieldDelimiter("1234567890abcdefghijklmnop"); fileRecord = readFile.read(); while (fileRecord) { line = con2str(fileRecord); info(line); fileRecord = readFile.read(); } } This is content of the text file: And that is the output generated with the code sample above: