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 :
Finance | Project Operations, Human Resources, ...
Answered

complicated display method filtering

(1) ShareShare
ReportReport
Posted on by
Hello,
 
I have a requirement of such difficult display method to be able to sort on and filter. Standard table ITMLine. method lineStatus()
 
 

   public display ITMLineStatus lineStatus()

 

   {

       ITMLineStatus shipLineStatus;  

       switch (this.RefTableId)

       {

           case tableNum(PurchLine):                

               shipLineStatus = this.lineStatusByPurchLine();

               break;

           case tableNum(InventTransferLine):                

               shipLineStatus = this.lineStatusInventTransferLine();                

               break;

           default:

               exceptionTextFallThrough();

       }

       return shipLineStatus;

   }

Therefore, I'll need view. But since the method is difficult involving if clauses and different tables is it possible to rewrite it using single computed column? As computed column is just SQl query then I guess it's not possible to achieve because the method is complicated? Or what should be the approach? 
 
Thanks.
I have the same question (0)
  • dark_knight Profile Picture
    on at
    complicated display method filtering
    many thanks for your help!
  • Sohaib Cheema Profile Picture
    User Group Leader on at
    complicated display method filtering
    In the last paragraph/lines, Martin is telling you about OOP(object Oriented Programming) approach. Rather than writing one big method (for the computed column), first break your work into multiple parts, for every part, try to make a view (if that is possible). eventually combine those parts/views into one computed column. This will make coding easy for you and it would make it look clean work. This is also sometimes due to the reasons that writing a big computed column with complex t-sql of nested level can be tricky at times, when done in X++. On it's own T-SQL is very easy to do (outside the X++)
     
  • Verified answer
    Martin Dráb Profile Picture
    Most Valuable Professional on at
    complicated display method filtering
    Yes, I already told you that is possible.
     
    But while writing the whole as a single large piece of T-SQL, you may be able to simplify it and write just some part is in SQL. For example, you could design AOT views returning PurchStatus and RemainStatus for each ITMLine, which is easier than designing T-SQL code for it and then writing X++ generating this SQL. But you don't have to - there are simply design decisions to make.
     
    Don't think about X++ functions such as  SysComputedColumn::if() yet. Before writing X++ generating SQL code, you need to know which SQL code you want to get. Design and test SQL code and only then write X++ code generating it.
  • dark_knight Profile Picture
    on at
    complicated display method filtering
    thank you Martin
     
    this last part of yours
     

    Note that you can often implement some parts of the logic as views that you'll use in the computed column, rather then generating everything as T-SQL from your code.

     
    what do you mean? could you pls clarify?
     
    As I see now, everything from method can be rewritten using one single computed column, right? for this I need to use SysComputedColumn::if() and other functions, right?
  • Suggested answer
    Martin Dráb Profile Picture
    Most Valuable Professional on at
    complicated display method filtering
    Yes, it can be done. You're wrong in thinking that T-SQL language so simple that it can't do things like conditions. It's actually very powerful (although not all features can be used in a column definition). In this case, you can open SysComputedColumn::if() method to see how it can be done in T-SQL.
     
    I reviewed all the code called from the method and there is nothing that can't be rewritten to T-SQL (just note that I didn't look at extensions). It'll require some effort, of course, but it's not extremely complicated.
     
    Note that you can often implement some parts of the logic as views that you'll use in the computed column, rather then generating everything as T-SQL from your code.

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

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Kumar_Sat Profile Picture

Kumar_Sat 32

#2
MF-16081018-0 Profile Picture

MF-16081018-0 24

#3
Karam Baazab Profile Picture

Karam Baazab 23

Product updates

Dynamics 365 release plans