Excel Import with Dialog

static void FixedAssetImport(Args _args)
{
    Num serialnumber;
    AssetTable assetTable;
    AssetId assetId;
    AssetGroupId assetGroupId;
    Dialog dialog;
    Filename filename;
    DialogField dialogFilename;
    //To filter the files while selecting
    container conFilter = ["Microsoft Excel 97-2003 Worksheet (.xls)" ,"*.xlsx"];
    
    //Excel
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    int row=1;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    dialog = new dialog();
    dialog.caption("select a file");
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    //To filter the files while selecting
    dialog.filenameLookupFilter(conFilter);
    dialog.run();
    
    if(dialog.closedOk())
    {
        filename = dialogFileName.value();
    }
    
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    
    do
    {
        row++;
        assetGroupId = cells.item(row,1).value().bStr();
        assetId = cells.item(row,2).value().bStr();
        serialnumber = cells.item(row,3).value().bStr();
        
        if( assetGroupId && assetId && serialnumber)
        {
            select forupdate AssetGroup,AssetId,Recid from AssetTable
                                    where assetTable.SerialNum == "" &&
                                    assetTable.AssetGroup == assetGroupId &&
                                    assetTable.AssetId == assetId;
        
            if(AssetTable.RecId)
            {
                assetTable.SerialNum = serialnumber ;
                assetTable.update();
            }
            else
            {
                error(strFmt("Please check the values for AssetId:%1",assetId));
            }
            
        }
        else
        {
            error(strFmt("Please check the values for AssetId:%1",assetId));
        }
        
        type = cells.item(row+1, 1).value().variantType();
    }
    while(type != COMVariantType::VT_EMPTY);
    
    workbooks.close();
    application.quit();
    
    info("Operation/Processing Completed");

}

Business Unit Lookup in Form

Just add the below code in lookup() of StringEdit control in Form to get the Business Unit Lookup:

public void lookup()
{
Query query;
SysTableLookup sysTableLookup;
super();

//DimAttributeOMBusinessUnit is a View
sysTableLookup = SysTableLookup::newParameters(tableNum(DimAttributeOMBusinessUnit), this);

sysTableLookup.addLookupfield(fieldNum(DimAttributeOMBusinessUnit, Value));
sysTableLookup.addLookupfield(fieldNum(DimAttributeOMBusinessUnit, Name));

query = new Query();

query.addDataSource(tableNum(DimAttributeOMBusinessUnit));

sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();

}

Choose File in ax Dialog

Below is the job to choose the selected file through the Dialog box.

static void DialogFilePath(Args _args)
{
    Dialog          dialog;
    Filename        filename;
    DialogField     dialogFilename;
    //To filter the files while selecting
    container      conFilter = ["Microsoft Excel 97-2003 Worksheet (.xls)" ,"*.xlsx"];
    //container    conFilter = ["Comma Seperated Value .txt ", "*.csv"];
     ;

    dialog = new dialog();
    dialog.caption("select a file");
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    //To filter the files while selecting    
    dialog.filenameLookupFilter(conFilter);
    dialog.run();

    if(dialog.closedOk())
        {
            filename = dialogFileName.value();
            box::info(filename);
        }
}

Simple Dialog

Do you ever feel how to make a dialog field as Mandatory, if so then follow as below
Make the Dialog Field mandatory as true as shown below:


 Dialog dialog;
 DialogField dialogField;
 ;
 
 dialog = new Dialog("Dialog Test");
 dialog.addText("Select customer:");
 dialogField = dialog.addField(extendedTypeStr(CustAccount));
 dialogField.label("Re-Name");// TO Re-Name the Field Name in Dialog
 dialogField.mandatory_RU(true);// To make Dialog as mandatory
 dialogField = dialog.addField(enumStr(Gender));//To get Enum in dialog box
 
 dialog.run();
 
 if (dialog.closedOk())
 {
 info(dialogField.value());
 }