26 Nisan 2019 Cuma

AX 2012 - Add computed column to view.

When we add a computed column to AX view what we do actually is adding extra keywords to SQL Server view without any errors.

First we add a table method to AX view:

public static server str SNBisBuggedReverse()
{
return strFmt("select top 1 sign(sum(accountingcurrencyamount)) from GENERALJOURNALACCOUNTENTRY g "+
"where isnull(%1,'') <> '' and exists (select * from TRANSACTIONREVERSALTRANS t where t.TRACENUM = %1 and t.REFRECID = g.RECID and t.REFTABLEID = %2) "+
"group by g.LEDGERACCOUNT "+
"order by 1 desc",SysComputedColumn::comparisonField(identifierstr(PAXMizanView), identifierstr(TransactionReversalTrans), identifierstr(TraceNum)),
 tableNum(GeneralJournalAccountEntry));
}

Seem at up we just use SQL Server query keywords, not AX. Our method will return a string like that:

select top 1 sign(sum(accountingcurrencyamount)) from GENERALJOURNALACCOUNTENTRY g where isnull(T4.TRACENUM,'') <> '' and exists (select * from TRANSACTIONREVERSALTRANS t where t.TRACENUM = T4.TRACENUM and t.REFRECID = g.RECID and t.REFTABLEID = 3119) group by g.LEDGERACCOUNT order by 1 desc

We want to add an Enum field as type NoYes. Than:




After that we select our table methods name from ViewMethod property:




My computed column was unfortunately made my view so slow, we should faster things as possible as we could for create a fast view.

Hiç yorum yok:

Yorum Gönder