Search through blog..

Wednesday, October 24, 2012

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 choose New 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.
  5. By using the table browser, you can now add records to MyTable.



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.

2 comments:

vani said...

hey ajith, u done a gud job of posting this, but one small suggestion, change your theme because u written something above the first image unable to see, if no one able to see, no use of your blog.. take it as positive feedback...:-)

Ajit said...

Hey Vani.. Thanks much for your feedback :)
I have changed the initial blog theme and after that I have this issue in few my early blogs. Slowly correcting them. Will do so for the rest too.
Maybe it is time to speed up :) Thanks again..