Hello DAXPeople,
Today we are going to see, how all the tables in AOT can be fetched using some standard framework.
The below code snippet will be having two AOT objects.
- Runnable class (GetAOTTablesList) : This class will have main business logic to loop through AOT tables
- Table (AOTTablesList) : This table will be used to store the Table Label, Name, ID, Group and ConfigurationName.
Here is the code snippet written on Runnable class: GetAOTTablesList-
internal final class GetAOTTablesList
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
AOTTablesList tablesList;
System.Collections.IEnumerator tableCollectionEnumerator;
delete_from tablesList;
ttsbegin;
var query = Microsoft.Dynamics.AX.Metadata.NodeLib.Specialized.TableQuery::Construct();
query.AllowTemporary = false;
query.AllowSystem = true;
tableCollectionEnumerator = query.GetEnumerator();
while (tableCollectionEnumerator.MoveNext())
{
GetAOTTablesList::createTableRefRecord(tableCollectionEnumerator.Current as Microsoft.Dynamics.AX.Metadata.NodeLib.Node);
}
ttscommit;
}
internal static void createTableRefRecord(Microsoft.Dynamics.AX.Metadata.NodeLib.Node _node)
{
AOTTablesList tablesList;
SysDictTable dictTable = new SysDictTable(tableName2Id(_node.Name));
tableId tableId = dictTable.id();
if (dictTable && dictTable.enabled())
{
// don't include views, temp tables, in memory tables, dixf staging tables, transaction, dataentity
if ( DictTable.isView() || dictTable.tableType() != TableType::Regular || dictTable.tableGroup() == TableGroup::Staging
|| dictTable.tableGroup() == TableGroup::Transaction || dictTable.isDataEntity())
{
return;
}
tablesList.TableIdValue = tableId;
tablesList.TableObjectName = dictTable.name();
tablesList.TableLabel = dictTable.label();
tablesList.TableGroup = dictTable.tableGroup();
tablesList.ConfigName = configurationkeyId2pName(dictTable.configurationKeyId());
tablesList.insert();
}
}
}
Refer below the Table structure & Fields:
At the end, if you want to execute the runnable job, create an Action menu item and add it to your custom module or any existing module.
After adding the menu item button, click on it.
Job will then be executed and you will be able to see records getting created in the table.
Here is the output of job execution.
Happy Daxing.. !!
No comments:
Post a Comment