Using Computed Columns in Microsoft Dynamics AX 2012

By Laura Lake | April 8, 2015

Table-browser

One of the complaints I hear most from customers is the inability to filter & sort on display methods. We have the ability in AX 2012 to use Computed Columns to add computed values to a view, and the interesting part is that these columns do support sorting and filtering. There are a few very good blogs online already showing examples of using computed columns with Sum() and other aggregate functions, but the intention here is to explore the possibility of having a computed column that is in itself a Select statement.

This example assumes the reader has knowledge of Views in AX. There is also a walkthrough on MSDN showing how to add a Computed Column to a View.

Walkthrough: Add a Computed Column to a View

My view has only CustTable as its DataSource. The AccountNum field will be displayed, and the Name field is my Computed Column.

Computed Column Example

Note that the properties on the Computed Columninclude a ViewMethod property. The getName static method is as follows…

static server str getName()
{
return SysComputedColumn::getDirPartyNameFromParty(tableStr(CustView),identifierStr(CustTable),fieldStr(CustTable,Party));
}

(Note: The hard-coding in this example is intentional. I believe it helps to make the concept easier to understand for those who are new to it.)
I have created a new method in the SysComputedColumns class to return the Select statement which will be executed on SQL Server.

public static server str getDirPartyNameFromParty(TableName _viewName,
str _DataSourceParty,
str _DataSourcePartyField)
{
str expression;
expression = ‘select name from dirpartytable where recid = ‘ +
SysComputedColumn::returnField(_viewName,
_DataSourceParty,
_DataSourcePartyField);

return expression;
}

SysComputedColumns has many built-in methods we can use as well, like the ReturnField method which here returns the value from the Party field in our CustView.

The resulting view looks like this, and notice I have clicked on the Name column to sort in Name order!

Table Browser
Finally, I am not advocating the use of computed columns to replace display methods under normal circumstances. However, sometimes our customers have business needs that require us to use whatever tools we have at our disposal. The possibilities here are intriguing but also dangerous. Think about how your views might be impacted by upgrades for one thing. With great power comes great responsibility!

For additional tips check out my post: More on Using Views in Dynamics AX 2012

Related Posts

Recommended Reading:

5.13.22 Power Platform

Using Power BI Object Level Security

  The following article will demonstrate how to use Power BI Object Level Security to disable column data based on […]

Read the Article
5.12.22 Dynamics CRM

How to Use the Stoneridge Support Portal

Stoneridge Software’s support portal is an intuitive and useful function that makes it easy for you to access resources to […]

Read the Article
5.6.22 Dynamics GP

Dynamics GP Transaction Removal: Purchase Orders

  Are you having performance issues with Purchase Orders?  Do you find that there are old Purchase Orders on your […]

Read the Article
5.5.22 Dynamics GP

The Real Story about the Long-Term Future of Dynamics GP Support

I’ve seen a number of people put forward comment that Dynamics GP is going away and you have to get […]

Read the Article

New Features in Dynamics 365 Business Central 2022 Wave 1 Release Part 3 – Financial Enhancements

The Dynamics 365 Businses Central 2022 Wave 1 Release has a lot of new and exciting features to help your […]

Read the Article
4.29.22 Dynamics GP

Dynamics GP Transaction Removals: Bank Reconciliation

  This is part 2 of a 3 part series on Dynamics GP Transaction Removals. These quick tips will hopefully […]

Read the Article
4.28.22 Dynamics GP

Uncommonly Used Features – Integrate Purchasing and Payables to Fixed Assets in Dynamics GP

Being able to integrate Purchasing and Payables to Fixed Assets in Dynamics GP will help you create visibility for your […]

Read the Article

New Features in the Dynamics 365 Business Central 2022 Wave 1 Release Part 2 – Ease-of-Use Features

  There are many new features in the Dynamics 365 Business Central 2022 Wave 1 Release to get excited about! […]

Read the Article
4.22.22 Dynamics GP

Dynamics GP Transaction Removal Series: Receivables

  This is part 1 of a 3 part series on Dynamics GP Transaction Removal. These quick tips will hopefully […]

Read the Article

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X