Monday, March 17, 2014

Table Inheritance in Ax 2012

In Microsoft Dynamics AX 2012, tables can inherit, or extend, from the tables that are situated above them in a hierarchy. 
A base table contains fields that are common to all tables that derive from it
- The table properties "Extends", "SupportInheritance" are used in the table inheritance hierarchy
- Table inheritance hierarchy can only be defined on a normal table type but not on tempdb, InMemory
- A type discriminator field must be defined on any table inheritance hierarchy created in the AOT. 
the field must be defined as an int64 type on the root table, with the name of the field set to InstanceRelationType. 
Furthermore, the developer must select this field as the value for the InstanceRelationType table property on the root table.
- In all the tables of inheritance hierarchy, the SupportInheritance property is set to Yes.Extends is set to the required tables
Do not create any fields in the table before completing the table hierarchy
Note: Field names must be unique across the entire table inheritance hierarchy. 
This requirement ensures that the field name uniquely identifies the field across the hierarchy 
when appearing in system APIs that reference table fields. 
Developers will also notice that field IDs are unique across the entire table inheritance hierarchy
- If you are displaying the instance type of the record on a form, and a report is needed then a enumerationt ype can be defined on the  base table with the values as the types of tables in the hierarchy
Override the insert table method on the base table and write the code as follows
For eg: Partytype enum on party table

DictEnum enumType = new DictEnum(enumnum(partytype));
int enumValue;
if (this.DisplayRelationType != partytype::Unknown)
{
return;
}
enumValue = enumType..symbol2Value(this.getInstanceRelationType());
if (enumValue == 255) // symbol2Value returns 255 if cannot convert
{
throw error(strfmt('No %1 enum element found for EnumValue %2',
enumstr(partytype),
this.getInstanceRelationType()));
}
else
{
this.DisplayRelationType = enumValue;
}
super();
- 
Developers can now use a new developer tool, the Type hierarchy browser to visualize the table inheritance hierarchy in a more intuitive way. 
Developers can access the tool by right clicking the AOT Tables node, 
and then clicking Add Ins > Type hierarchy browser

Saturday, February 22, 2014

Create ssrs reports in ax 2012

Reports in Microsoft Dynamics Ax 2012 are based on SQL Server reporting services (SSRS)
SSRS

Before designing and executing the Report, SSRS needs to be configured.

We can use a Query as a datasource or use report data provider class.

1. Using a query as datasource :

    --  Create a new query in AOT TestQuery with required datasource

    --  Open visual studio and create a new Dynamics AX project
 
   

   -- Select Microsoft Dynamics AX from the installed templates -> report model and name the model

   

  -- Add a new report to the newly created report Model as shown below

  

  -- Then add the dataset to the newly created report.
      Right click on the datasets node and chose the option New datset
      Set the Query property to the newly created query.
      Then you can select the desired list of fields.
 --  Under the design section you can create 2 types of design, auto design and precision design
 --  Auto design arranges the fields and layout automatically whereas in precision we can customize the       design
--  Select the dataset and drag and drop on to your designs node it creates an auto design
     Under the design node we can select multiple properties to control the report preview

--  After completing the above steps rt. click on report model and select add to AOT property to deploy      the report

--  When we come back to Ax the report can be seen in below path
      AOT ->  Visual studio projects -> Dynamics AX Model projects
      AOT ->  SSRS Reports -> Reports

--  After this we can create a output menu item and select the newly created report in the properties.
     to execute the report.

2. Using Report data provider.
 

   --> For this first we need a temp table to store the report data and create required fields.
   --> It is best to decide on the fields of table before starting the design of the report in  
          visualstudio designer
   --> Once the table is completed we need to create controller, contract and data provider classes
   --> After this a new Dynamics Ax model project can be created in visual studio and a new               
         report can be added as in the above section.
   --> When adding the dataset to the report set the newly created data provider class
   --> Under the design node you can select a new precison design and start designing the report
         based   on your requirement
   --> After completing the above steps rt. click on report model and select add to AOT property to
         deploy the report