How to get a Table Id from a Table Name and vice versa

In this quick post I want to show you how to get a Table Id from a given Table Name and also how to get the Table Name for a given Table Id.

Table Name to Table Id

To get a Table Id for a given Table Name you want to have a look at the global tableName2Id method. In my example I set the EDT TableName to “CustTable” and the method will return the Id as an integer.

static void TableNameToTableId(Args _args)
{
TableName tableName = "CustTable";
TableId tableId = tableName2id(tableName /* Table Name */);
info(strFmt("TableId for '%1' is %2", tableName, tableId)); // 77
}

AX2012 Table Name to Table Id

Table Id to Table Name

As we have our Table Id we can “convert” it back to the Table Name. Take a look at the global method tableId2name. This method will return a string, the Table Name.

static void TableIdToTableName(Args _args)
{
TableName tableName = "CustTable", myTableName;
TableId tableId = tableName2id(tableName /* Table Name */);
myTableName = tableId2name(tableId /* TableId */);
info(strFmt("Table Name for '%1' is %2", tableId, myTableName)); // CustTable
}

AX2012 Table Id to Table Name

You may also like...