August 20, 2015

Computed Columns in View Microsoft Dynamics AX 2012 Part 2

From Part 1, there is 2 column is Computed Column., CalculatedReal and ItemName. On part 1 was described how to create field CalculatedReal and on this part will be described how to make field ItemName.

We will create computed column to show Name alias(Search name) on view CPTransView.


At first, create a method with named compColItemName with detail code like below

public static server str compColItemName()
{
    #define.ViewName("CPTransView")
    #define.DataSourceName("CustPackingSlipTrans")
    #define.FieldItemId("ItemId")

    str         sItem, translationSQL, ret;
    DictView    dictView;
    ;

    dictView = new DictView(tableNum(#ViewName));

    sItem = dictView.computedColumnString
            (#DataSourceName,
             #FieldItemId,
             FieldNameGenerationMode::FieldList,
             true);

    translationSQL = strFmt("SELECT NameAlias FROM InventTable WHERE InventTable.ItemId = %1 AND DataAreaId = '%2'",
                     sItem, CompanyInfo::find().dataArea);


    ret = strFmt("%1", translationSQL);

    return ret;
}


that methode return field NameAlias on InventTable.

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


then, set properties of that new field like a picture below


If all finished, try to open the view


0 comments:

Post a Comment