Creating a Dynamics AX Table and Table variables


While creating a new Micrsoft Dynamic Ax Table, it is very important that you initially consider how our new tables are going to be used. Because when the new tables are installed in a live application, and after the data has been entered to the tables, it will be more complex to redesign the tables. 

If we want to add additional fields on an existing table, you might have chosen to create a new table with the required fields. And each time you need to access the new fields you will have to join the new table with the existing table. This can be frustrating, and slower, so it is very important to concentrate on the Design before creating tables.

Creating a table:
Let consider a table to store customer information is to be created.
1.       Create a new table by going to the Tables node in the AOT, right-click and chooseNew Table. A new table called "Table1" will be created. Open the property sheet and rename the table to "MyFirstTable".
2.      Expand the new table node so the nodes at the next level are visible. Open another instance of the AOT and go to Data Dictionary/Extended Data Types. Locate the extended data type AccountNum and drag the extended data type AccountNum to the Fields node of MyFirstTable.

3.      Locate the extended data types CustName, CustGroupId and CurrencyCode and then drag them all to the Fields node of MyTable.

4.      Save the table by pressing ctrl+s at the MyTable node. The table is now synchronized to the database and you have created your first table.

By using the table browser, you can now add records to MyTable. 
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbk9u6TT4c-cim9JMrCZXl5QJDHNqBeQz9KpILDlhUiGqjWsciL1_ardGoPQTPo9GN3OM9_Mw_v7cIxK0rnLtLkCbdvJlovhu-HhrcZPggjJu0pCBIijeN11XeswNQ8y4dAGw2rK7Zx_fN/s640/Post8_TBView_MyFirstTable.jpg

When creating a new record notice that the fields' custGroupId and currencyCode both have a lookup button and only values from the related lookup table can be chosen. This is because of the extended data types we used. This way, for these two fields we have created a relation to the tables CustGroup and Currency. 
So now, Without any coding you have already created a new table with relations !!


Table variables
Tables are declared in X++ like any other variable. To initiate a table variable with a value from the database select statements are used. You can also set a table variable equal to another as long as both tables variables are of the same type.

Example(1):
static void DataDic_OneCursor(Args _args)
{
CustTable custTable, newCustTable;
;
select firstonly custTable;
newCustTable = custTable;
}

In this example with the CustTable, only one cursor position will exist if one table variable is set to equal another. If one of the table variables is used to select another record, both table variables will point to the new record.


Example(2):
static void DataDic_TwoCursors(Args _args)
{
CustTable custTable, newCustTable;
;
select firstonly custTable;
newCustTable.data(custTable);
}
To have two separate cursors the method data() must be used. Now the table variable custTable and newCustTable will each have a cursor.


Comments

Popular posts from this blog

Write/ Read to Excel Sheet

Table Methods in Ax 2012

Financial Dimensions in AX 2012