Extract data of PO from the System in Ax 2012

 static void Job(Args _args)

{

    PurchTable      purchTable;

    PurchLine       purchLine;

    Dialog          dialog  = new Dialog();

    DialogField     dialogFieldFileSave;

    Commaio         file;

    container       line;

    FilePath        TempPath;


    dialogFieldFileSave     = dialog.addField(extendedTypeStr(FilenameSave),"File path","Caption here");

    dialog.caption("Extract PO data");

    dialog.filenameLookupFilter(['*.csv']);


    if(!dialog.run())

    {

        return;

    }


    if (dialogFieldFileSave.value() == '')

    {

        error("Please set up the location for export file.");

        return;

    }


    TempPath = dialogFieldFileSave.value() + '.csv';


    #define.filename(TempPath)

    #File


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

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

    {

        throw error("File Cannot be opened");

    }


    //Put headers

    line = ["PO number","Vendor name","Vendor Id","line Id","Net price","Qty ordered","Product unit price","Unit value","SKU","Item description","PO date"];

    file.writeExp(line);

    //Put a sample line

    while select firstOnly100 PurchId, PurchName, OrderAccount from purchTable

        order by purchTable.PurchId

        join LineNumber, LineAmount, PurchQty, PurchPrice, PurchUnit, ItemId, createdDateTime from purchLine

        where purchTable.PurchId == purchLine.PurchId

    {

        line = [purchTable.PurchId, purchTable.PurchName, purchTable.OrderAccount, purchLine.LineNumber, purchLine.LineAmount, purchLine.PurchQty, purchLine.PurchPrice, purchLine.PurchUnit, purchLine.ItemId, purchLine.itemName() ,purchLine.createdDateTime];

        file.writeExp(line);

    }


    info(strFmt("File exported successfully. Please find it at %1",TempPath));


}

Comments

Popular posts from this blog

Assembly reference containing type is not referenced, Object 'CLRObject' could not be created

Send email using .Net framework

Make Partial and Fully Product Receipt of PO also make Partial and Fully Invoicing of PO in ax 2012 using X++