Wednesday, 7 October 2015

How to Customize Selector in Acumatica

Hi Everyone,

Sometimes you want to add additional selector column to the screen, but this process not always is super strait forward.
Acumatica Selector
I will try to guide you step by step, how to add additional address line column to location selector on Sales Orders Screen.

First of all lets create a new customization try to analyse this selector control.
If you select this field and check attributes, that you can can see that there is no selector attribute, but we have strange LocationIDAttribute. Actually selector is there, but it is hidden by LocationIDAttribute. Sometimes to accumulate some logic in one attribute, Acumatica developers uses special types attributes - PXAccumulatorAttribute. This attribute has a collection of other attributes inside. During runtime, Acumatica framework will check that our attribute is inherited from Accumulator and will add all nested attributes in the PXCache.

LocationIDAttribute
In this code you can see that PXDimensionSelectorAttribute (that is real selector attribute) is added to protected collection on all attributes.
LocationID Attribute inheritance flow:Acumatica Selector Attributes Inheritance
Ok, but how to customize selector columns? And here Acumaita frameworks, starting from version 5.0 has super nice feature - additional attribute that will customize selector columns even if selector is nested. Just specify PXCustomizeSelectorColumns and define columns that yoг want to see.
[PXCustomizeSelectorColumns(
typeof(PX.Objects.CR.Location.locationCD),
typeof(PX.Objects.CR.Location.descr),
typeof(PX.Objects.CR.Address.addressLine1))]
You can add this attribute manually, or using visual designers. Do the following:
  1. Select required field in DAC customization window.
  2. Click Selector Columns
  3. In this popup panel you will see all current selector columns
  4. Click Add Columns
  5. Here you will see all available columns for this selector.
  6. Try to filter columns by "Address"
Acumatica Customization Browser for Selectors
Actually, there is no any address in the list of available columns, except Default Address - this is a link to another DAC, that holds address information.
So we have to add a join condition from our selector to address table using this field. Please, refer to where we have a source code of LocationIDBase Atrribute and notice there an additional constructor parameter - JoinType.

Lest just customize the LocationID attribute with additional Join condition and lets add PXCustomizeSelectorColumns  with address field as well.
Acumatica Customization Browser

There result customization code is here:

Now you can just publish the customization and use your new super nice user interface.

No comments: