Sunday, December 20, 2020

Export data to CSV file - JOB AX 2012

static void JobExportWorker(Args _args)

{

    HcmWorker                               hcmWorker;

    CommaTextIo                           file;

    container                                   line;

    #define.filename(@'C:\Worker.csv')

    #File

    file = new CommaTextIo(#filename, #io_write);

    if (!file || file.status() != IO_Status::Ok)

    {

        throw error("File cannot be opened.");

    }

    file.outRecordDelimiter('\r\n');

    file.outFieldDelimiter('\t');


    while select hcmWorker

    {

            line = [hcmWorker.personnelnumber,hcmWorker.Name()];

            file.writeExp(line);

    }

    info(strFmt("File %1 created.", #filename));

}