How to create progressbar in dynamics ax


Description:-

In this article we will see how to create progress bar in ax through code. In my one of project while importing some big data it’s taking more time to import in table so for display purpose I have to display to user some background process is going on so he/she can’t do more action on that form or anyother form in ax otherwise it will goes in NotResponding Status. So for that I have set Progressbar to display how many rows imported and still how many remaining to import in table. Here is the code to create simple progress bar in dynamics ax.

Here I have created job for create progressbar to understand easily. Using Excelsheet example I have import some big data in table while import data I have set progressbar on that.

Code:-

staticvoid ReadExcel(Args _args)
{
    SysExcelApplication application,excelApp;
    SysExcelWorkbooks workbooks,excelWorkBooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet,excelWorkSheet;
    SysExcelCells cells,excelCells;
    COMVariantType type,type1;
    COM                     excelCOM;
    int row1;
    SysOperationProgress simpleProgress;
    Int lastRow;
    DataArea dataAreaCount;
    BaseDate datetype;
    #AviFiles
    ;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    filename = "C:\\Users\\umesh.adroja\\Desktop\\Code and Excel\\DayBook - Final.xlsx";
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(3);
    cells = worksheet.cells();
    excelCOM = cells.comObject();
    excelCOM = excelCOM.SpecialCells(11);   // 11 = xlCellTypeLastCell
    lastRow = excelCOM.Row();               // Row for the last cell
    simpleProgress = SysOperationProgress::newGeneral(#aviUpdate, 'going through process', lastRow);
    do
    {
        row++;
        simpleProgress.incCount();
        simpleprogress.setText(strfmt("Updated rows:%1 remaining %2", row,lastRow-row));
        simpleprogress.update(true);

        type = cells.item(row+1, 2).value().variantType();
        type1 = cells.item(row+1, 3).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY || type1 != COMVariantType::VT_EMPTY);
    application.quit();
}

Related Posts

Previous
Next Post »

Thanks for comments.....