AX – D365FO – Computed columns in Views examples

Computed columns have been using in SQL server since many versions but this feature was available Dynamics AX since version 2012.
Follow steps described here to learn how to create view and walthrough the complete example to understand how can we add computed columns in AX 2012 Views.
More examples can be found from here –> http://daxmusings.codecrib.com/2011/10/computed-view-columns-in-ax-2012.html

Well, here is an example which illustrates how can we add computed columns in a view with different logic.


Computed column; Returning Field in View

public static server str compAmount()
{
   #define.CompView(SWProjForecastCost)
   #define.CompDS(ProjForecastCost)
   #define.CostPrice(CostPrice)


   return SysComputedColumn::returnField(tableStr(#CompView), identifierStr(#CompDS), fieldStr(#CompDS, #CostPrice));
} 


Computed column; Returning Enum Value in View

public static server str compGeneralTransType()
{
   return SysComputedColumn::returnLiteral(Transaction::ProjectInvoice);
}


Computed column; Multiplying two coulmns and returning resultant from View

private static server str compTotalCostPrice()
{
   #define.CompView(SWProjForecastCost)
   #define.CompDS(ProjForecastCost)
   #define.QtyCol(Qty)
   #define.PriceCol(CostPrice)


   return SysComputedColumn::multiply(
           SysComputedColumn::returnField(
               tableStr(#CompView),
               identifierStr(#CompDS),
               fieldStr(#CompDS, #PriceCol)
           ),
           SysComputedColumn::returnField(
               tableStr(#CompView),
               identifierStr(#CompDS),
               fieldStr(#CompDS, #QtyCol)
           )
         );
}

Computed column; Case Statement in View

public static server str TransType()
{
   #define.CompDS(ProjForecastCost)
   #define.CompView(SWProjForecastCost)
   str ret;

   str ModelId = SysComputedColumn::returnField(identifierStr(SWProjForecastCost), identifierStr(ProjForecastCost), identifierStr(ModelId));

   ret = "case " + modelId +
         " when 'Sales' then 'Forecast Sales' " +
         " when 'Orders' then 'Forecast Orders' " +
         " when 'Latest' then 'Forecast Latest' " +
         " end";
   return ret;


}



Case Statement for this view looks like in SQL server as below;

   CASE T2.MODELID
      WHEN 'Sales' THEN 'Forecast Sales'
      WHEN 'Orders' THEN 'Forecast Orders'
      WHEN 'Latest' THEN 'Forecast Latest' END

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...