To Implement Reusable Business Logic
If you need to use the same business logic in multiple parts of your MYOB Acumatica application or MYOB Acumatica Framework-based application and this logic is not included in the source code of MYOB Acumatica, you can define your own generic graph extensions, for which this topic provides detailed instructions.
To view a list of predefined generic graph extensions, see Generic Graph Extensions Declared in MYOB Acumatica.
To Create a Generic Graph Extension
- In the code of your application, define the mapped cache extensions, which
inherit from the PXMappedCacheExtension
abstract
class. For details on the mapped cache extensions, see Mapped Cache Extension.//Mapped cache extension public class Document : PXMappedCacheExtension { //BAccountID field public abstract class bAccountID : IBqlField { } protected Int32? _BAccountID; public virtual Int32? BAccountID { get { return _BAccountID; } set { _BAccountID = value; } } //CuryID field public abstract class curyID : IBqlField { } protected String _CuryID; public virtual String CuryID { get { return _CuryID; } set { _CuryID = value; } } ... }
- In the code of your application, define the generic graph extension as
follows:
- Define a class inherited from the
PXGraphExtension<TGraph> class. The following
code shows a declaration of a generic graph extension.
public abstract class MultiCurrencyGraph<TGraph, TPrimary> : PXGraphExtension<TGraph> where TGraph : PXGraph where TPrimary : class, IBqlTable, new() { }
- In the generic graph extension, for each mapped cache extension that you
defined in the first step, declare the
protected
mapping class, as shown in the following code. For details on the mapping classes, see Mapping Class.//A mapping class protected class DocumentMapping : IBqlMapping { public Type Extension => typeof(Document); protected Type _table; public Type Table => _table; public DocumentMapping(Type table) { _table = table; } public Type BAccountID = typeof(Document.bAccountID); public Type CuryInfoID = typeof(Document.curyInfoID); public Type CuryID = typeof(Document.curyID); public Type DocumentDate = typeof(Document.documentDate); }
- In the generic graph extension, for each mapping class, declare the
protected abstract
method that returns the mapping class, as shown in the following code.protected abstract DocumentMapping GetDocumentMapping();
- In the generic graph extension, define the views that use the mapped
cache extensions, as the following code shows. To define each view, you
use the PXSelectExtension<Table> :
PXSelectBase<Table> class, where
Table is a mapped cache
extension.
//A view that uses the mapped cache extension public PXSelectExtension<Document> Documents;
Note: In the generic graph extension, you can define standard views as well as the views that use the mapped cache extensions. - In the generic graph extension, define the reusable event handlers, as
the following code
shows.
protected virtual void _( Events.FieldUpdated2<Document.documentDate, Document> e) { if (e.Row == null) return; CurrencyInfoAttribute.SetEffectiveDate<Document.documentDate>( Documents.Cache, new PXFieldUpdatedEventArgs(e.Row, e.OldValue, e.ExternalCall)); }
- In the generic graph extension, implement any other business logic that you want to reuse, such as filters and actions.
- Define a class inherited from the
PXGraphExtension<TGraph> class. The following
code shows a declaration of a generic graph extension.
Once you have defined the mapped cache extensions and the generic graph extension, you can insert reusable business logic in any part of your application, as described in To Insert Reusable Business Logic That Has Already Been Declared.