Sunday, November 3, 2019

List all tables, include Table group description and company status for Microsoft Dynamics AX 2012 R3

static void Z_ListTable(Args _args)
{
    TextIo file;
    FileName filename = @"F:\TableList.txt";
    container con;
    FileIoPermission permission;
    #File

    TableId         tableId;
    SysDictTable    sysDictTable;
    TableGroup      tableGroupx;
    NoYes           isPerComp;
    String255       tableName;
    int             tablecounter;
    Dictionary      dict = new Dictionary();
    EnumId   Id        = enumNum(TableGroup);
    DictEnum dictEnum  = new DictEnum(Id);
    int             EnumValue;
    ;

    try
    {
    permission = new FileIoPermission(filename, #io_write);
    permission.assert();
    file = new TextIo(filename, #io_write);
    if (!file)
    throw Exception::Error;
    file.outRecordDelimiter(#delimiterCRLF);
    file.outFieldDelimiter(";");

        for (tablecounter=1; tablecounter<=dict.tableCnt(); tablecounter++)
        {
            tableId         = dict.tableCnt2Id(tablecounter);
            sysDictTable    = new SysDictTable(tableId);

            if (sysDictTable && !sysDictTable.isTmp() && !sysDictTable.isMap())
            {
                tableGroupx  = sysDictTable.tableGroup();
                EnumValue = enum2Int(tableGroupx);

                isPerComp   = sysDictTable.dataPrCompany();
                tableName   = sysDictTable.name();

                con = connull();
                con = conins(con, 1, tableName);
                con = conins(con, 2, tableGroupx);
                con = conins(con, 3, dictEnum.index2Symbol(EnumValue));
                con = conins(con, 4, isPerComp);

                file.writeExp(con);
            }
        }

    }
    catch(Exception::Error)
    {
        error("You do not have access to write the file to the selected folder");
    }
    CodeAccessPermission::revertAssert();

    info('File Created!');

}

No comments:

Post a Comment