Tuesday 26 February 2013

Extension Framework in AX2012


Introduction:


The basic idea of extension framework is that Frameworks, and their Foundation components  must adhere to the Open-Closed principle. This principle states that “software entities should be open to extension, but closed to modification”  this means that extending framework classes should not require changes to the any framework artifacts (classes, tables, Enums).

I found a great post on this..


Enjoy ...

Wednesday 20 February 2013

Display Methods in Ax 2012


Display Methods :


These methods are commonly used while performing a calculation or to lookup fields from another table. The
Display modifier is added before the method name that shows that the methods return value is to be displayed on forms and reports.






Please note that the return type of a display method should be of type EDT.

Usage:


The Display modifier can be used on .


  • Table methods.
  • Form methods.
  • Form datasource methods.
  • Report methods.
  • Report design methods.
Avoid complex calculations on display methods because they are called each time a form is redrawn.

I will be demonstrating the usage of display methods  by a quick example.

  • Add a display method to lookup fields from another table on a form datasource.





  • This is how the method looks.

















As , you can see the methods lookup WorkItemType from another table that is'nt available under the datasource node of this form.


  • Add the display method to a form control.


















  • Change the Data source and Data method properties of the control as follows.










It's better to write Display methods on the table level so that the same method can be used on multiple forms and reports where the table is used as a Datasource.

If the value returned is to be shown in a grid then the Display method must be written on the form datasource level as shown in our example above.

I believe it was useful ..



Thursday 14 February 2013

Reading excel file to store data in a table in Ax 2012



   
Today I will be sharing how to read excel in Ax 2012 . I will demonstrate through a simple example.

Below is my Excel Sheet .


This is my Job that reads this excel sheet.

static void ExcelJobProduct(Args _args)
{

SysExcelApplication                    application;
SysExcelWorkbooks                   workbooks;
SysExcelWorkbook                     workbook;
SysExcelWorksheets                  worksheets;
SysExcelWorksheet                    worksheet;
SysExcelCells                              cells;
COMVariantType                       type;
ProductType                                prodType;
FileName                                     filename;
Product                                         Product;
ProductId                                     prodId;
Name                                           productType;
int                                                 row =1 ;
str                                                ProductName;
real                                              Price;
str                                               _ProductCode;


application = SysExcelApplication::construct();
workbooks = application.workbooks();

//specify the file path that you want to read
filename = "C:\\Task_2_DataSet_Normalized.xlsx";
try
{
//  Adds the file as the first document in the collection.
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}

workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(5);   // represents the current worksheet in my case it's (5)
cells = worksheet.cells();

// Fetches data from each cell that contains data.

do
{
row++;

Price       = cells.item(row, 4).value().double();
prodId      = int642str(cells.item(row, 1).value().double());
ProductName = cells.item(row, 2).value().bstr();
productType = cells.item(row, 3).value().bStr();

// Insert data into Product table based on the ProductType from ProductType table.
select prodType
     where prodType.ProductType == productType;

if(prodType.RecId != 0)
 {
    ttsBegin;
    Product.ProductCode  =  prodId;
    Product.Name              = ProductName;
    Product.ProductType   = prodType.RecId;
    Product.Price                =  Price;
    Product.insert();
    ttsCommit;
 }
type = cells.item(row+1, 1).value().variantType();
}

// Runs until the COMVarientType doesnot contains a data field.
while (type != COMVariantType::VT_EMPTY);

// Closes the Instance of Excel.
application.quit();
}


Here ,
  • SysExcelApplication  represents an instance of Excel .
  • SysExcelWorkbooks provides collection of Excel documents stored in this Class.
  • SysExcelWorkbook   provides a reference to the opened document.
  • SysExcelWorksheets represents a collection of all the worksheets in a document.
  • SysExcelWorksheet   provides a reference to a single worksheet.
  • SysExcelCells             provides reference to the collection of cells within a sheet.
  • COMVariantType      COMVarient Class is used to store various types of data .



Monday 4 February 2013

Difference Between OLTP and OLAP

OLTP:



  • Operational data; OLTP's are the original source of the data.
  • To control and run fundamental business tasks.
  • Short and fast inserts and updates initiated by end users.
  • Relatively standardized and simple queries Returning relatively few records.
  • Backup religiously; operational data is critical to run the business, data loss is likely to entail significant monetary loss and legal liability.




OLAP:



  • Consolidation data; OLAP data comes from the various OLTP Databases.

  • To help with planning, problem solving, and decision support.
  • Periodic long-running batch jobs refresh the data.
  • Often complex queries involving aggregations.
  • Instead of regular backups, some environments may consider simply reloading the OLTP data as a recovery method.