Interview Questions

Monday, May 12, 2014

InventoryOnHand AX report with ItemName & Warehouse info in ax 2009

InventoryOnHand AX report with ItemName & Warehouse info. 
Today we’ll create a report look like standard Dynamics AX 2009 “InventOnhand” report but with some modifications which are adding ItemName & Warehouse info.
First: Create new report:
  1. Open AOT from toolbar or by Ctrl+O.
  2. Right click on Reports, & choose new report.report3
Second: Data query:
  1. We need basic information from InventSum & InventDim tables.
  2. In AOT right click on Tables and choose New window.report7
  3. Drag InventSum table into report’s DataSource.
  4. Drag InvnetDim table into InventSum’s DataSource.
  5. Create relation between two tables by adding new relation under InventDim DataSource and choose new relation.report6
  6. In relation choose InventDimId column in two tables.report4
Now we had the same data in the standard report, but as requirement we need the ItemName & Warehouse info, we’ll do it by using Data Methods.
Third: Data Method:
We need to get the ItemName for the ItemId field in InventDim (make sure) table, so we’ll write some X++ code in data method, let’s start coding:
  1. Right click on Report’s Method node and choose New method.report8
  2. Rename method to ItemName, make it return str (String) value with size 40 and Display property.
  3. Inside method we’ll write code to get the ItemName from InventTable for the ItemId in InventSum table.
?
1
2
3
4
5
6
7
8
9
//Get Item Name
display str 40 ItemName()
{
    str result;
    InventTable inventTable = InventTable::find(InventSum.ItemId);
    ;
    result = inventTable.itemName();
    return result;
}
?
1
  
Syntax:
?
1
2
//ItemId from the InevntSum Table DataSource
TableClass tableObject = TableClass::find(InventSum.ItemId);
Then we need to get the Inventory ID and name for the InventLocationId field in InventDim (make sure) table, so we’ll write some X++ code in data method, let’s start coding:
  1. Right click on Report’s Method node and choose New method.
  2. Rename method to WarehouseName, make it return str (String) value with size 45 and Display property.
  3. Inside method we’ll write code to get the Inventory ID and name from InventLocation for the InventLocationId in InventDim table.
?
1
2
3
4
5
6
7
8
9
10
//Get Warehouse Id and Name
display str 45 WarehouseName()
{
    str result;
    ;
    result = inventDim.inventLocation().InventLocationId + " " + inventDim.inventLocation().Name;
    return result;
}
Note: in the code above I didn’t use TableClass::find() method to get information from InventLocation Table, because there are two methods implemented in InvenDim TableClass to get the warehouse information.
Fourth: Design:
  1. Right click on Design and choose new design.report2
  2. Right click on AutoDesignSpecs and choose Generate specs from Query.report5 
  3. Drag required field from DataSource & drop them on InventSum_Body
  4. Right click on InventSum_Body New –> String, Give it name for example ItemName.
  5. Right click on ItemName and choose properties.
  6. In properties window add Label for the field “Item Name” & DataMethod = ItemName.report1
  7. Repeat steps 4,5, & 6 but for Warehouse; give it name “Warehouse”, Label = “Warehouse”, & DataMethod = WarehouseName.
  8. Save report and run it.
report9

No comments:

Post a Comment