New feature in Dynamics AX 2012 - NeedsRecord property on Buttons.

In Dynamics AX 4.0 and 2009, if a button's action depended on a record being present, we usually added code in the executeQuery() method of the datasource to check for the existence of a record. If a record was not found, the button was disabled.

Scenarios like these required specific code to be written by the developers. With Dynamics AX 2012, this has change. There is a new property NeedsRecord introduced on all button controls, these include your plain buttons, menu item buttons and command buttons as well. Menu button groups do not have this property.

The NeedsRecord property works in conjunction with the DataSource property. Now we know that the normal buttons and command buttons do not have a DataSource property? So what happens in that case?

The answer is the DataSource property is inherited from the parent of the button. This could be a button group or a tab page. If the button group also doesn't have the DataSource property set, then the kernel looks for the next parent. This process is repeated till it finds the parent (or shall we say the grand parent) which has the DataSource property set. In most cases, this will be the design node.

Introduction of this property has reduced a lot of work on the developer's part. Imagine if you wanted to disable 10 buttons, then you needed to add those many lines of code for them. So the next time, you have a requirement like this, you know what property to set.

Thats all for today guys. Do check back soon for more.


Popular posts from this blog

How to add empty ranges in query

Get selected records in Dynamics AX 2012

The field with ID '0' does not exist in table - Cause and resolution.