Tuesday, June 2, 2020

Computed Coulmn in Views AX

Here are some examples of Computed column. Create string field in view using computed column and then add any one method from below to that field.

1. Calculate field in View using SysComputedColumn code.

public static server str getOutstanding()
{
    return strFmt("Sum(%1) + Sum(%2)",
            SysComputedColumn::returnField(
            tableStr(TIDIndentOrderUninvoiceTrans),
            identifierStr(TIDIndentOrderPaymentTrans),
            fieldStr(TIDIndentOrderPaymentTrans, amountTendered)),
            SysComputedColumn::returnField(
            tableStr(TIDIndentOrderUninvoiceTrans) ,
            identifierStr(TIDIndentOrderPaymentTrans),
            fieldStr(TIDIndentOrderPaymentTrans, grossAmount)));
}



2. Convert null Date to Max Date in view using SysComputedColumn code.

public static server str ReleasePostingDate()
{
 
    return SysComputedColumn::if(
            SysComputedColumn::isNullExpression(SysComputedColumn::returnField(
            tableStr(TIDAPUninvoiceConsignmentItem) ,
            identifierStr(LedgerJournalTableRealease),
            fieldStr(LedgerJournalTable, PostedDateTime))),
            SysComputedColumn::cast(strFmt("'%1'",DateTimeUtil::date(DateTimeUtil::maxValue())),'NVARCHAR'),
            SysComputedColumn::cast(SysComputedColumn::returnField(
            tableStr(TIDAPUninvoiceConsignmentItem) ,
            identifierStr(LedgerJournalTableRealease),
            fieldStr(LedgerJournalTable, PostedDateTime)),'NVARCHAR')
            );
}

3.