Tuesday, March 31, 2015

Computed columns in Views - Dynamics AX 2012

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;


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; Converting UTC Date to Date in View
public static server str compDate() { #define.CompView(SWProjForecastCost) #define.CompDS(ProjForecastCost) #define.ActualDateTime(ActualDateTime)
str sDateTime;
sDateTime = SysComputedColumn::returnField(tableStr(#CompView), identifierStr(#CompDS), fieldStr(#CompDS, #ActualDateTime));
   return SysComputedColumn::fromUtcDateToDate(sDateTime); }

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


Till next post Happy Daxing :)

5 comments:

  1. Investment plansPROMO PACKAGE ?? BASIC Invest $70 earn $600 Invest $100 earn $1000  Invest $200 earn $2,000  Invest $300 earn $3,500  Invest $400 earn $4,500  Invest $500 earn $6,000 
    ?? PRO  Invest $1,000 earn $15,000  Invest $2,000 earn $25,000  Invest $3,000 earn $35,000  Invest $4,000 earn $45,000  Invest $5,000 earn $60,000  Invest $10,000 earn $100,000. 
    ?? PREMIUM  1BTC earn 5BTC  2BTC earn 10BTC  3BTC earn 16BTC  4BTC earn 22BTC  5BTC earn 30BTC. 
    ALL RETURNS ARE SCHEDULE, FOR 12 HOURS, UPON CONFIRMATION OF PAYMENTS.
    MODE OF PAYMENT. Any, Suitable For Investors, But Terms and Conditions Apply.
    ??HURRY NOW!!! Refer a Friend or Family member to invest same time, and Receive an instant $50 Reward. 
    To set up an INVESTMENT PLAN, Contact Admin: totalinvestmentcompany@gmail.com
    WhatsApp: +1(929)390-8581
    https://www.facebook.com/pg/Total-Investment-221964325813140/about/
    https://t.me/totalinvestment

    ReplyDelete
  2. My name is Jane Wembli Josh and i live in the USA California and life is worth living right now for me and my family and all this is because of one man sent by GOD to help me and my family, i once had a life filled with sorrow because my first SON needed a kidney transplant and all our savings were going towards his medications and this normally leaves us with no money to pay our bills or even put enough food on our table and our rent was due and no funds to pay these bills and life felt so unfair to me and every night my wife will cry herself to sleep every night until one day, i was browsing through yahoo answers and i saw a striking advert of a man that gives out personal loans and that the offer is opened to all and i have heard so many things about internet scams but at this point of my life, i was very desperate and ready to take any risk and at the end of the day, i applied for this loan and from one step to another, i got my loan within 12 hours through bank transfer and you know, it was all like a dream and i called Rev. Fr. Kevin Doran A Man who is the GOD sent lender i found and said, i have received my loan and he smiled stating that to GOD be the glory and i was so shocked as i have never ever seen anyone with such a GOD fearing and kind heart and today, i am the happiest man on earth because by GOD’S grace, my SON kidney transplant was successful and today he is healthy, i and my family are living very comfortable and happy and if you are in my former situation or in serious and legitimate need of a loan, you can reach this GOD sent lender via consumerloanfirm@gmail.com

    ReplyDelete
  3. invest funds as little as $ 200 and start earning $ 2000 weekly, alot of people has benefited from this investment offer this pandemic,the cryptocurrencies trades market has been doing wonders if you need help paying bills and you want to start making profit weekly contact Whats-App: +27633586789 or email wilsontradeszone@gmail.com

    ReplyDelete
  4. HAVE YOU LOST YOUR MONEY TO BINARY OPTION SCAM OR ANY ONLINE SCAM WHATSOEVER?.DO YOUR DESIRE CREDIT REPAIR[EQUIFAX, EXPERIAN, TRANSUNION? WELL, YOU HAVE FOUND REDEMPTION IN ASORE CORP.



    Asore Corp is a group of multinational Hacker's, an affiliate of Evil Corp. We make sure by all means necessary that our clients get the best of services on a🔐PAYMENT AFTER JOB IS DONE BASIS✅. Rather than send money and trust a criminal to fulfill your deal, you can make sure the job is done before WORKMANSHIP is paid for. You'll get excellent customer service.

    That's a 100% guarantee. Our Cyber security Technicians are on standby 24/7 to receive your job requests.



    ⚠️ BEWARE OF FRAUDSTARS looking to hoax.

    if you have been a VICTIM, contact : ✉️cyberprecinct@gmail.com for directives.

    Here, it's always a win for you.



    🔸OUR SERVICES🔸

    ➡️Binary Option funds recovery

    ➡️Social media hack

    ➡️Recovery of loan scam

    ➡️Credit repair (Equifax,Experian,Transunion)

    ➡️Email hack

    ➡️College score upgrade

    ➡️Android & iPhone Hack

    ➡️Website design

    ➡️Website hack

    And lots more.



    DISCLAIMER: Asore Cyber Corp accepts no responsibility for any information,previously given to anybody by clients on as regarding the job. Asore Cyber Corp will not distribute contact information collected on any hacking job other than in the Asore corps Hacker's listings themselves, and will not sell contact information to third parties.



    CONTACT INFO:

    📧 asorehackcorp@gmail.com

    cyberprecinct@gmail.com



    Copyright ©️

    Asore Cyber Corp 2021.

    All rights reserved.

    ReplyDelete
  5. Are you a business man or woman? And you are in need of an urgent loan as to start up your own business? Or do you have a low credit score and you are finding it hard to obtain capital loan from local banks and other financial institutes? Interested applicants should Contact us via Email.robertrichardloanfirm332@gmail.com
    for a loan offer of 2% Our loans are well insured for maximum security is our priority, Our leading goal is to help you get the services you deserve, Our program is the quickest way to get what you need in a snap.. Reduce your payments to ease the strain on your monthly expenses.for more info about getting this loan,Email:robertrichardloanfirm332@gmail.com or whatsapp us on this number +1(929)251-1161

    ReplyDelete

I will appreciate your comments !

Download large bacpac (sandbox database) to DEV environment much faster

As the LCS website gets slower and slower and the database backups get bigger and bigger.  Use AZCopy to download objects out of LCS asset l...