To Implement Reusable Business Logic
You can define your own generic graph extensions when:
- You need to use the same business logic in multiple parts of your MYOB Acumatica application or MYOB Acumatica Framework–based application.
- This logic is not included in the source code of MYOB Acumatica.
This topic provides detailed instructions. To view a list of predefined generic graph extensions, see Generic Graph Extensions: Classes Declared in MYOB Acumatica.
To Create a Generic Graph Extension
- In the code of your application, define a class that inherits 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, define the mapped cache extensions, which
inherit from the PXMappedCacheExtension
abstractclass. For details, see Mapped Cache Extension.//Mapped cache extension public class Document : PXMappedCacheExtension { //BAccountID field public abstract class bAccountID : PX.Data.BQL.BqlInt.Field<bAccountID> { } { } protected Int32? _BAccountID; public virtual Int32? BAccountID { get { return _BAccountID; } set { _BAccountID = value; } } //CuryID field public abstract class curyID : PX.Data.BQL.BqlString.Field<curyID> { } { } protected String _CuryID; public virtual String CuryID { get { return _CuryID; } set { _CuryID = value; } } ... } - For each mapped cache extension, declare the
protectedmapping class, as shown in the following code. For details, 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); } - For each mapping class, declare the
protected abstractmethod that returns the mapping class, as shown in the following code.protected abstract DocumentMapping GetDocumentMapping(); - 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;Tip: In the generic graph extension, you can define standard views as well as views that use the mapped cache extensions. - 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)); } - Implement any other business logic that you want to reuse, such as filters and actions.
Once you’ve defined 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.
