Tuesday, 3 January 2017

Append and Replace of DACs Attributes

Hi Everyone.

Today want so share with you some ideas on how you can append, replace or merge attributes on standard Acumatica's data access classes.
Acumatica Framework attributes are used to add common business logic to the application components. Attributes implement business logic by subscribing to events. Each attribute class directly or indirectly derives from the PXEventSubscriberAttribute class. B

Most attributes are added to data access class (DAC) field declarations. There are also attributes that are placed on a DAC declaration, view declarations in a business logic controller (BLC), and the BLC declaration itself. In general there are 4 places where you can define attributes:
  • DAC attributes
    • DAC fields. You can define attributes on property that represents database column.
    • DAC Extension (PXCacheExtension). That extensions are very similar to data access classes itself. You also can define attributes on properties that represents fieds
  • Graph Attributes
    • Graph CacheAttached method. That method has special naming convention to identify DAC and field. That method never be executed by the platform so you should not put any logic there. All attributes are just defined on method itself. Great benefit of defining attributes on CacheAttached method is that you can have different attributes (and logic) in different screens.
    • Graph Extension (PXGraphExtension). Similar to previous one but defined inside graph extension class.
But what if you define some attributes in all these places? Deferentially, Acumatica has some priorities and rules how to merge attribute that was defined in different places into one single place -PXCache. PXCache belongs to graph Graph and manages one single DAC with all related attributes.

Priority for attribute definition:
  • DAC
  • PXCacheExtension
  • PXGraph
  • PXGraphExtension
That means that if you have attriibutes in DAC, you can replace it with PXCacheExtension
If you attributes on Graph's CachecAttached method you can replace it with PXGraphExtension
Graph and Graph Extensions has bigger priority because they define logic that would be used on specific screen. So with CacheAttached method you can replace attributes that are defined on DAC and all DAC extensions together.

When you redefine attributes for specific fields you also can use 3 rules:
  • MergeMethod.Append  - Means that new attributes should replace originals
  • MergeMethod.Replace - Means that original attributes should be replaces. 
  • MergeMethod.Merge - Means that platform can automatically merge 2 lists of attributes to replace redefined and append not existing.
Please note that if MergeMethod is not specified than Acumatica will use Replace behavior.
But the recommended way is to use Append or Merge option everywhere where it is possible. That will help you to e more protected from base code changed. If Acumatica adds new attribute on that field (like Formula) that with Append or Merge option it would be used automatically. With replace option you will have an issue.

Here I have several examples that you can use to understand how does it work.

Scenario
DAC
DAC Extension
Graph CacheAttached
Graph Extension CacheAttached
Runtime in PXCache
DAC Attributes Only
PXUIField
PXDBString





PXUIField
PXDBString
DAC and CacheAttached

PXUIField
PXDBString

PXDBString
PXSelector



PXDBString
PXSelector
DAC and CacheAttached
Explicit Append Option
PXUIField
PXDBString

PXMerge (Append)
PXDefault




PXUIField
PXDBString
PXDefault
DAC and CacheAttached
Explicit Replace Option

PXUIField
PXDBString

PXMerge (Replace)
PXDBString

PXDBString
DAC and CacheAttached
Explicit Replace Option
PXUIField (“AAA”)
PXDBString

PXMerge (Merge)
PXUIField (“BBB”)
PXDefault




PXDBString
PXUIField (“BBB”)
PXDefault
DAC and DAC Extension
PXUIField
PXDBString
PXDefault
UIField
PXDBString
PXSelector





UIField
PXDBString
PXSelector
DAC and DAC Extension
Append Option
PXUIField
PXDBString
PXSelector





PXUIField
PXDBString
PXSelector
DAC, DAC Extension and CacheAttached
PXUIField
PXDBString
UIField
PXDBString
PXSelector
PXDBString


PXDBString
DAC, DAC Extension and CacheAttached
Append Option
PXUIField
PXDBString
PXMerge (Append)
PXSelector
PXMerge (Append)
PXDefault





PXUIField
PXDBString
PXSelector
PXDefault
DAC, DAC Extension, CacheAttached and Graph Extension Cache Attached

PXUIField
PXDBString
PXMerge (Append)
PXSelector
PXMerge (Append)
PXDefault
PXMerge (Replace)
PXDBString
PXDBString
DAC, DAC Extension, CacheAttached and Graph Extension Cache Attached
PXUIField
PXDBString
PXDefault
PXUIField
PXDBString
PXMerge (Replace)
PXDBString
PXUIField

PXMerge (Append)
PXSelector

PXUIField
PXDBString
PXSelector


Have a nice development!

No comments: