web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

X++ Computed View AX 2012

(0) ShareShare
ReportReport
Posted on by

This is my very first computed View Method, and was wondering if someone would tell me if I am going in the correct direction.  

The View name is ccv_HierarchyTreeTable (which uses the table - HierarchyTreeTable.).  I am using the two fields [Path] and [Element Number].  I am using the computed field as a sort field, so I can get the data in the correct order for a grid view in a form.

It returns two different strings depending on if Path is blank or not (am I using the correct/best way of checking for a blank string?)

If I followed the example I took this from, I should have:  public static server str cc_SortNode() -- why would it have server in that line?  

Anyway - following is my code.  Does it look correct?  Anything else I need to know?

_________________

public static str cc_SortNode()

{

 #define.ViewName(ccv_HierarchyTreeTable)

 #define.DataSourceName("HierarchyTreeTable_1")

 #define.FieldPath("Path")

 #define.FieldElement("ElementNumber")

 str sReturn,

     sPath,

     sElementNumber;

 DictView dictView2;

 dictView2 = new DictView(tableNum(#ViewName));

 sPath = dictView2.computedColumnString

     (#DataSourceName,

      #FieldPath,

      FieldNameGenerationMode::FieldList,

      true);

 sElementNumber = dictView2.computedColumnString

     (#DataSourceName,

      #FieldElementNumber,

      FieldNameGenerationMode::FieldList,

      true);

  if (spath == "")

  {

    sReturn = sElementNumber + "!" + sElementNumber;

  }

  else

  {

    sReturn = sPath + sElementNumber;

  {

  return sReturn;

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    dolee Profile Picture
    11,279 on at
    RE: X++ Computed View AX 2012

    Hi,

    What you are returning in this method should be a partial TSQL statement . The condition logic is to be included in it.

    In your case, that would mean you should look to return something like:

    CASE

     WHEN yourTable.[Path] = '' THEN yourTable.[Element Number] + '!' + yourTable.[Element Number]

     ELSE yourTable.[Path] + yourTable.[Element Number]

    END AS [My Field Name]

  • Community Member Profile Picture
    on at
    RE: X++ Computed View AX 2012

    sReturn = strFmt("CASE " + "WHEN %1 = '' THEN %2 + '!' + %2 ELSE %1 + %2 END", sPath, sElementNumber);

    So - that was helpful.  I changed my if statement to this, and now it compiles and works.

    BUT!!! - I don't understand this CASE statement.  This isn't standard X++ case statement is it?  Is this more of an SQL case statement?  Where would I go look this up so I can better understand what I am doing!  Thanks

  • Verified answer
    dolee Profile Picture
    11,279 on at
    RE: X++ Computed View AX 2012

    Yes, it is a TSQL statement syntax.

    What happen is the view in AOT is translated into SQL statements when synchronizing with database.

    When you have a computed column, the string returned by the view method is injected into the TSQL statement directly as a column definition.

    E.g.

    CREATE VIEW [dbo].[YourView] AS

    SELECT col1, col2, col3, <view method return value>

    FROM yourTable

    WHERE ....

    GO

  • dolee Profile Picture
    11,279 on at
    RE: X++ Computed View AX 2012

    Forgot to mention, so you just need to lookup TSQL CASE statement for more information.

    msdn.microsoft.com/.../ms181765.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans