Tuesday 24 June 2014

Select the batch tab in dialog by default using SysOperation controller class

Hi,
Many times we have use sysOperation framework without using any data contract. In that case, if you run the class to open the dialog you would see a blank tab. To select the batch tab by default just place this code in your controller class.

protected void dialogPostRun()
{
    sysOperationDialog sysOperationDialog;
    DialogTabPage batchTab;
    FormRun formRun;

    super();

    sysOperationDialog = this.dialog() as SysOperationDialog;

    formRun = sysOperationDialog.formRun();

    batchTab = sysOperationDialog.batchDialogTabPage();

    formRun.selectControl(batchTab.control());
}

Wednesday 18 June 2014

Generate Excel Template of AX 2012 tables-all columns

Hi, This job can be used in data migration when your client asks for a template of a particular table.

static void Wipfli_TemplateGenerator(Args _args)
{
    SysExcelWorksheetHelper worksheetHelper;
    SysExcelHelper          sysExcelHelper;
    SysExcelWorksheet       worksheet;
    int                     column = 1;
    int                     row = 1;
    str                     worksheetName;
    SysDictField            dictField;
    SysExcelCell            excelCell;
    int                     redColor = WinAPI::RGB2int(255, 0, 0);
    SysExcelRange           range;
    COMVariant              cellValue = new COMVariant(COMVariantInOut::Out);
    DictTable DictTable;

    int fieldCount, _x, fieldId,enumValues, enumValue;

    sysExcelHelper = SysExcelHelper::construct();

    sysExcelHelper.initialize();

    worksheet = sysExcelHelper.addWorksheet("Template");
    worksheetHelper = SysExcelWorksheetHelper::construct(worksheet);

    DictTable = new DictTable(tableNum(InventTable));// Use your table name here.

    fieldCount = DictTable.fieldCnt();
    fieldId = DictTable.fieldNext(0);

    while (fieldId)
    {
      DictField = DictTable.fieldObject(fieldId);
      worksheetHelper.addColumn(column, dictField.name(),Types::AnyType);

      fieldId = DictTable.fieldNext(fieldId);
      column++;
    }

    sysExcelHelper.launchExcel();

}