Saturday, February 15, 2014

Highlighting record in Grid

It is possible to use colours in grids on Axapta forms. This can be a useful method to highlight particular rows, or grid cells within a row, based on the data in the record.

The method displayOption() method on a form datasource can be over-ridden to control the appearance of an single row in a grid. It is possible to set the background or foreground (text) colour. Since this is a form datasource method, the FormRowDisplayOption affects not only the grid, but also the other controls on this form connected to the datasource.

This method is executed once for each record before the record is displayed on a form.

The following example overrides the displayOption method to set display options, and to override the background color for the particular record.

public void displayOption(Common _record, FormRowDisplayOption _options)
{
     SalesLine    salesLineLocal;
     if (salesLineLocal.ItemGroup == 'ABC')
     {
         _options.backColor(WinApi::RGB2int(255,255,0)); // Yellow  
     }
}



Sunday, February 9, 2014

Singleton pattern in X++

The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.
Generally, singleton classes use a static variable to hold a reference their own instance, but as Axapta does not support static variables we are left with no other option to use the global caching mechanism to accomplish the similar functionality. Due to the nature of Axapta global caching, we need to add the instance reference to both the client- and server-side caches separately.
We should override the new () method of our singleton class and use the private access modifier to ensure that it cannot be instantiated directly. For accessing the instance we will create static method which will act as static accessor method used typically in normal Singleton pattern implementation.

Saturday, February 8, 2014

Maximum and Minimum of RecId

Ever thought of getting the Maximum or Minimum value of of RecId, here is the method to find out.

maxRecId() which gives you Maximum RecId value
minRecId() which gives you Minimum RecId value

Output:

Max of RecId


Min of RecId