Today I was searching something and I got very interesting information for X++ So this below post is totally produce from ChatGPT.
In Dynamics 365 Finance & Operations (X++), [Hookable(true)], [Wrappable(false)], and [Replaceable] are method attributes that control how a method can be extended using Chain of Command (CoC) and pre/post event handlers.
1. Attribute comparison
| Attribute | Purpose | Effect |
|---|---|---|
[Hookable(true)] | Enables pre/post event handlers | Allows developers to subscribe to method events |
[Wrappable(false)] | Disables Chain of Command | Prevents developers from wrapping the method using CoC |
[Replaceable] | Allows skipping next in CoC | Enables a CoC wrapper to replace the original implementation |
2. Examples
[Hookable(true)]
Allows pre/post event handlers to be attached to a method.
[Hookable(true)]
public void processOrder()
{
info("Processing order");
}
A developer can create a pre-handler or post-handler for this method.
Important: Public methods are generally hookable by default, so explicitly specifying [Hookable(true)] is often unnecessary.
[Wrappable(false)]
Prevents developers from extending a method through Chain of Command.
[Wrappable(false)]
public void processOrder()
{
info("Processing order");
}
The following CoC extension is not allowed:
[ExtensionOf(classStr(MyClass))]
final class MyClass_Extension
{
public void processOrder()
{
next processOrder();
info("Custom logic");
}
}
Because the original method has [Wrappable(false)], the compiler rejects the wrapper.
[Replaceable]
Allows a CoC extension to conditionally skip calling next.
[Replaceable]
public boolean validateOrder()
{
return true;
}
Extension:
[ExtensionOf(classStr(MyClass))]
final class MyClass_Extension
{
public boolean validateOrder()
{
boolean result;
if (this.isSpecialOrder())
{
result = true;
}
else
{
result = next validateOrder();
}
return result;
}
}
Normally, CoC requires calling next. With [Replaceable], the wrapper can conditionally bypass the original implementation.
3. Can all three attributes be used together?
Consider:
[Hookable(true)]
[Wrappable(false)]
[Replaceable]
public void processOrder()
{
info("Original implementation");
}
There is a design contradiction here:
[Hookable(true)]allows event handlers.[Wrappable(false)]prohibits CoC wrappers.[Replaceable]permits a CoC wrapper to skipnext, but wrapping has already been disabled.
Therefore, [Replaceable] provides no practical benefit when [Wrappable(false)] is applied.
4. Recommended usage
| Requirement | Recommended attribute |
|---|---|
| Allow pre/post event handlers | [Hookable(true)] |
| Prevent event handlers | [Hookable(false)] |
| Prevent CoC extension | [Wrappable(false)] |
Allow CoC but require next | Default CoC behavior |
| Allow CoC to bypass original logic | [Replaceable] |
| Prevent both CoC and event handlers | [Hookable(false)] and [Wrappable(false)] |
Architectural recommendation: In D365 F&O, use [Replaceable] carefully because it allows extensions to bypass standard business logic, potentially including validations.
For methods involving inventory posting, financial journals, purchase orders, or other critical transactions, prefer CoC with mandatory next unless there is a specific business requirement to replace standard behavior.











