My previous post was about the augmentation approach in D365. We will look a little bit deeper with this post.
To summarize; Augmentation is a way to enrich (or extend) the current solution without (or minimum) risk of allowing intrusive changes. Augmentation can be considered as a way of inheritance but there are some critical differences. It also can be compared with event handlers but easier to write.
A few words about the terminology; name of the whole concept is Augmentation. Creating an extension of a method can be called as wrapping or CoC.
Advantages of Augmentation;
- Classes, tables, data entities or forms can be augmented.
- For classes [ExtensionOf(classStr(ClassA))]
- For tables or data entities [ExtensionOf(TableStr(TableA))]
- For forms, you should use seperate augmentation classes for each design element
- [ExtensionOf(formdatasourcestr(FormToExtend, DataSource1))]
- [ExtensionOf(formdatafieldstr(FormToExtend, DataSource1, Field1))]
- [ExtensionOf(formControlStr(FormToExtend, Button1))]
- Public and protected methods of a class (table, data entity or forms) can be wrapped.
- Public and protected variables are reachable.
- Inherited classes (child classes) can also be augmented.
- Sometimes you need to think about the inconsistency between inheritance and augmentation principles. There are solutions for it.
- If there are methods that should never be augmented can be marked as [HookableAttribute(false)] or [Wrappable(false)].
- A final method which is marked as [Wrappable(true)] can also be wrapped.
- You can make the next call inside a try – catch block (added with PU 21)
Restrictions of CoC;
- When wrapping a method which has parameters with a default value, wrapper method should not include or change that default parameter.
- Characteristic properties of the method (signatures) cannot be edited. Access type (public or protected), parameter types, parameter list and return type must remain the same.
- Augmentation classes can’t be augmented. Nested augmentation is not supported.
Restrictions of Next call;
- Always call next unless the referred method explicitly marked as “Replaceable”.
- next call must be done at the root level;
- It can’t be controlled inside a conditional statement like if – else or switch – case blocks
- It can’t be called inside loops like while, do – while or for loops.
- Method can’t be prematured with an early return call.
Keep in mind that, most of the time intellisense support for CoC is not available yet. So you should use good – old copy paste technique until it will be available.
Ray (Emre) TUFEKCI