Translate

Showing posts with label Dyanaimcs AX. Show all posts
Showing posts with label Dyanaimcs AX. Show all posts

Thursday, August 4, 2011

Writing Data to CSV file from Dyanamics AX

Here is a code to write date from Microsoft Dyanics Ax to comma separated file(.csv).

static void AX2CSV(Args _args)
{
    CommaTextIO file;
    container line;
    InventTable invenTable;
    #define.filename('u:\\items.CSV')
    #File
    ;
    file = new CommaTextIO(#filename, #io_write);
    if (!file || file.status() != IO_Status::Ok)
    {
        throw error("File cannot be opened.");
    }
    file.outFieldDelimiter(';'); // for semicolon seperator and default field delimitter is ,(comma)
    while select invenTable
    {
        line = [invenTable.ItemId,invenTable.ItemName,invenTable.ItemGroupId];
        file.writeExp(line);
    }
}
Good Luck.. :)

Thursday, July 28, 2011

Reading data from txt file

static void ReadDateFromTxtFile(Args _args)
{
    #File
    TextIo                  io;
    container               c;
    str               itm, name;
    ;
    io = new TextIo("U:\\Test.txt", #io_read);
    if (!io)
    {
        throw error("Error reading file");
    }
    io.inFieldDelimiter(','); //This can be any delimiter, I'm just using Semicolon as an example
    io.inRecordDelimiter(#delimiterCRLF); //CRLF = Carriage Return Line Feed
    ttsbegin;
    while (io.status() == IO_Status::Ok)
    {
        c = io.read();
        if (io.status() != IO_Status::Ok)
        {
            break;
        }
        itm = conpeek(c, 1);
        name=  conpeek(c, 2);
        info(itm + '-->' + name);
    }
    ttscommit;
}

Writing Data to Excel file

//X++ Code to write data from AX to Excel sheet

static void WriteAX2ExcelFile(Args _args)
{
InventTable inventTable;
SysExcelApplication excel;
SysExcelWorkbooks books;
SysExcelWorkbook book;
SysExcelWorksheets sheets;
SysExcelWorksheet sheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
excel = SysExcelApplication::construct();
books = excel.workbooks();
book = books.add();
sheets = book.worksheets();
sheet = sheets.itemFromNum(1);
cells = sheet.cells();
cells.range('A:A').numberFormat('@');
cell = cells.item(1,1);
cell.value("Item");

cell = cells.item(1,2);
cell.value("Name");
row = 1;
while select inventTable
{
row++;
cell = cells.item(row, 1);
cell.value(inventTable.ItemId);
cell = cells.item(row, 2);
cell.value(inventTable.ItemName);
}
excel.visible(true);
}

Wednesday, July 27, 2011

How to avoid the scaling info message while running reports

Avoiding the info message of scaling when the report is displayed.

Include this code either in init() or fetch() method


this.printJobSettings().suppressScalingMessage(True);


Hope This Will helps you to get rid of Irritating scaling message.. :)

Regards,
Prasan