Using Computed Columns in Microsoft Dynamics AX 2012

by | Updated August 15, 2016 | Development, Dynamics AX

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 [AX 2012]

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

  • Since the release of Microsoft Dynamics 365, there have been a lot of rumors around when Microsoft support for Dynamics AX 2009 and Dynamics AX 2012 will end. Microsoft Dynamics AX support…

  • This post is meant especially for new users of Microsoft Dynamics AX. I think it is important to be aware of different shortcuts that are available to help your speed and ease…

  • Have you ever found yourself applying the same filter to a list page in Microsoft Dynamics AX 2012 over and over? If so, this quick and easy tip will save…

1 Comment

  1. srikanth konda

    Great post Laura. Thanks

Trackbacks/Pingbacks

  1. More on Using Views in Microsoft Dynamics AX 2012 | Stoneridge Software Inc - […] a follow up to my last blog, Using Computed Columns in AX 2012 , I wanted to share a few more…

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events

august

13aug11:00 am12:00 pmConfab with Stoneridge - Livestream - Inspire Keynote Breakdown

19aug10:00 am11:00 amWhat is Levridge? An Overview of the Ultimate Ag Solution

19aug12:00 pm12:30 pmThe Modern Manufacturer - Death by Safety Stock

27aug12:00 pm1:00 pmConfab with Stoneridge - Livestream - Dynamics 365 2020 Wave 2 Preview

september

02sep10:00 am10:30 amThe Modern Manufacturer - Cycle Count Management

09sep10:00 am11:00 amWhat is Levridge? An Overview of the Ultimate Ag Solution

16sep10:00 am10:30 amThe Modern Manufacturer - Product Lifecycle Management

30sep10:00 am10:30 amThe Modern Manufacturer - Return Management

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X