Generate a view column based on column data

  • Generate a view column based on column data

    Posted by DSC Communities on January 19, 2017 at 1:17 pm
    • Andy Norton

      Member

      January 19, 2017 at 1:17 PM

      I’ve created a view that uses the InvoiceAmountMST column.

      I’d like another column to be a string “Invoice” if this value is positive, if this value is negative “Credit”.

      I’ve taken a look at Computed View Columns in AX, although I’m not 100% sure this is the right method?

      A first attempt below, I’m stuck at how to get a numeric value from the dictView and then return a string after checking for negative figures (if this is indeed the right way to go)

      public static server str getInvoiceType()
      {
          #define.CompView(GBCustInvoiceJourView)
          #define.CompDS(CustInvoiceJour_1)
          #define.InvoiceAmountMSTCol(InvoiceAmountMST)
          str invoiceAmount;
          DictView dictView;
          ;
         
          dictView = new DictView(tableNum(GBCustInvoiceJourView));

          invoiceAmount = dictView.computedColumnString(identifierStr(CustInvoiceJour_1),
              fieldStr(GBCustInvoiceJourView, InvoiceAmountMST),
              FieldNameGenerationMode::FieldList,
              true);
         
      }

      ——————————
      AX 2012 R2
      ——————————

    • Colby Gallagher

      Member

      January 19, 2017 at 9:09 PM

      Yup, computed columns on a view can do this just fine.  Try this:

      private static server str getInvoiceType()

      {

          TableName ViewName = identifierstr(GBCustInvoiceJourView);

          str CustInvJour = identifierstr(“CustInvoiceJour_1”);

          str invoiceAmount, sReturn;

         

      invoiceAmount = sysComputedColumn::ReturnField(ViewName, CustInvJour, fieldStr(CustInvoiceJour, InvoiceAmountMST));    

       

       

      sReturn = “Select Case when ” +invoiceAmount + “>0 THEN ‘Invoice’ Else ‘Credit’ END “;

             

          return sReturn;

           

      }

      ——————————
      Colby Gallagher
      Manufacturing Systems Consultant
      Agility Business Solutions
      Brecksville OH
      ——————————
      ——————————————-

    • Andy Norton

      Member

      January 29, 2017 at 10:58 AM

      This worked perfectly, thanks!

      ——————————
      AX 2012 R2
      ——————————
      ——————————————-

    DSC Communities replied 8 years, 7 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘Generate a view column based on column data’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!