August 20, 2015

Computed Columns in View Microsoft Dynamics AX 2012 Part 1

Computed columns in view is a very useful feature in Microsoft Dynamics AX 2012. To understand it, let me show an example

I have a query named CPTransQuery with structure like a picture below

 From that query, I create a view named CPTransView with structure like a picture below

Let's see 2 field with name CalculatedReal and ItemName is a calculated field


How to make it ?
At first, create a method with named getCalculated() with detail code like below

public static server str getCalculated()
{
    return  SysComputedColumn::multiply(
            SysComputedColumn::divide(
                              SysComputedColumn::returnField(tableStr(CPTransView),
            identifierStr(CustPackingSlipTrans),
            fieldStr(CustPackingSlipTrans,Qty)),
            SysComputedColumn::returnField(tableStr(CPTransView),
            identifierStr(InventTrans),
            fieldStr(InventTrans,Qty)) ),
            SysComputedColumn::returnField(tableStr(CPTransView),
            identifierStr(CustPackingSlipTrans),
            fieldStr(CustPackingSlipTrans,ValueMST)) )
            ;
}

that methode calculated :
(CustPackingSlipTrans.Qty / InventTrans.Qty * CustPackingSlipTrans.ValueMST

After it, right click on node Fields on  CPTransView and then select New->Real Computed Column



 Set properties of new field like a picture before. If you have finished all step, let's try to open view :

1 comments:

Post a Comment