/trud-d365fo-xpp:d365-xpp-extensionsfrom D365FO X++ Development
Provides rules and recipes for extending Dynamics 365 Finance & Operations X++ code via Chain of Command, event handlers, form extensions, lookups, and dialog fields. Use when writing or reviewing extension classes.
Ships in D365FO X++ Development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
How to write and review extensions of standard D365 F&O code: Chain of Command (CoC) wrappers, event handlers, form extensions, lookups and dialog fields.
This skill sits on top of what you already know. It doesn't explain [ExtensionOf], next, data events, XppPrePostArgs, EventHandlerResult, SysTableLookup, SysPackExtensions or context classes. It holds the rules that are easy to get wrong from memory, the signatures and names that are hard to produce reliably, and recipes to copy.
Where a rule here differs from what you remember or from Microsoft Learn, follow this skill. Unless Rules that were not run lists it, every rule about compile or run-time behaviour was compiled and run on application version 10.0.39, and the samples were compile-checked there. On a much newer version, verify a rule when the result depends on it.
Samples use the prefix ABC (members abc…) and the model ContosoCustomizations. Use the prefix and model you work in.
Other skills in this plugin cover the rest: d365-xpp-conventions for the names of extension and handler classes, d365-xpp-xref to find the extension class a model already has, d365-xpp-compile for the task's project and the build.
Ax*.xml: signature, access modifier and attributes ([Hookable(false)], [Wrappable(false)], [Replaceable], final). [Hookable(false)] is common, so check it before you plan a wrapper. Visual Studio doesn't list the methods nested in a form that can be wrapped; take those from the form's XML or from Forms.d365-xpp-xref (-ExtensionsOf), or search the model's AxClass folder, case-insensitive, for ExtensionOf\(\s*tableStr\(\s*SalesLine\s*\) (real code has tablestr, Classstr, FormDataSourcestr).d365-xpp-conventions (Extensions). Every method and field you add gets the prefix.AxClass file, class attributes and using lines go in <Declaration> before class, member variables inside the declaration braces, and method attributes inside that method's <Source> above the signature. <Method><Name> equals the X++ method name.references/forms.md for form code, references/lookups.md for a lookup, references/dialogs.md for a RunBase or SysOperation dialog.d365-xpp-compile after every change, and run a full build before you finish: some errors, such as a wrong display-method binding, are reported by a full build only.next, nothing more: every pattern in Patterns that compile and are wrong compiles. For a form change, check in the client that the wrapper runs, the standard behaviour still runs and the form still saves, or say that this wasn't checked.| Need | Use |
|---|---|
| Change or add to what a public or protected method does | A CoC wrapper. This is the default. |
The method can't be wrapped, but it is public and not [Hookable(false)] | A pre/post handler. |
| Logic that belongs to the table: defaults, derived fields, related rows | CoC on the table method. |
| Another feature only observes the table | A data event handler. |
| The standard code raises a delegate for this purpose | A delegate subscriber. |
| React to a form, data source or control event | A form event handler; CoC on the nested element when you need code on both sides of the call or the form's state. |
Can be wrapped:
protected internal methods, and methods of a final class;insert, update, validateWrite, …), even when the table doesn't override it;Global (isConfigurationkeyEnabled, strRemoveCr, …), through [ExtensionOf(classStr(Global))]; the wrapper runs for unqualified calls;defaultRow();Can't be wrapped: private; internal, even in the same model; [Hookable(false)]; [Wrappable(false)]; a final method without [Wrappable(true)].
Pre/post handlers attach to public methods only. A protected target is compile error InvalidPrePostTarget unless it carries [Hookable(true)]. Private methods, [Hookable(false)] methods and a kernel table method that the table doesn't override are compile errors too.
public wrapper of a protected method is error ChainOfCommandMethodAccessModifierMismatch.public void create(boolean _append). Keeping = false is a compile error.static on a static method.next.next may standtry, finally, using, unchecked (…), changecompany (…), a plain { } block, and between ttsbegin and ttscommit.ChainOfCommandNextCallMustBeUnconditioned): inside if, a loop, switch or catch; in a logical expression; a second next; after if (…) { return …; }.[Replaceable] base method: next may be conditional or left out.next compiles in its methods, and only there. A path that skips next write() leaves that record unsaved while the parent record is saved, so check every path.To stop it, throw before next. This compiles, and it is the only way to stop a method that isn't [Replaceable]:
public void post()
{
if (!this.abcCanPost())
{
throw error("Posting is blocked for this journal.");
}
next post();
}
To make it do nothing for your caller only, change the argument it receives. The flag is a field of the extension class that the caller sets through a parm method:
protected void printReport(CustInvoiceJour _custInvoiceJour) // illustrative base method: it prints when it gets a record
{
CustInvoiceJour forReport = _custInvoiceJour;
if (abcSkipReport) // set by the caller through abcParmSkipReport(true)
{
forReport = null;
}
next printReport(forReport);
}
this.field. Private fields and methods are out of reach.static fields, with initialisers: private Set abcProcessedRecIds = new Set(Types::Int64);, private static boolean abcSkipValidation;. A public field is visible on the target (myClass.abcState = 12;); prefer private plus a parm method.public TransDate abcParmTransDate(TransDate _transDate = transDate) { transDate = _transDate; return transDate; }public when callers of the target use them, private for helpers. A protected one compiles with warning NotCoCProtectedMethodInExtensionClass and can be called only inside the class.DuplicatedMethodExtension). This is why every added member carries the prefix.#DEFINE, #LOCALMACRO) are allowed in the declaration of an extension class, so the RunBase pack pattern (#CurrentVersion, #CurrentList) works there.new() of the extension class (no parameters) doesn't run when the target is created. It runs before the first use of an extension member. Don't put anything in it that must happen at construction.methodStr(…) returns only the method name. methodStr(<Target>, m), methodStr(<Target>_<Model>_Extension, m) and formMethodStr(<Form>, m) are the same string at run time; the class you name only has to contain m for the compiler.[ExtensionOf] on a class that holds only static event handlers. It compiles and does nothing.[ExtensionOf(tableStr(<Entity>))]. View: viewStr(<View>).Global go in the model's existing Global extension class. A new one is declared final static class.unchecked (Uncheck::XDS) { next …; }. Don't toggle XDSServices.setXDSState.System.IDisposable with a method named Dispose, capital D. dispose doesn't compile.Open a context around the call and read it in a wrapper deeper down. This also works in a wrapper of a Global function. That wrapper runs for every unqualified call in the application, so keep it cheap and let the context decide:
[ExtensionOf(classStr(Global))]
final static class Global_ContosoCustomizations_Extension
{
static str strRemoveCr(str s)
{
str ret = next strRemoveCr(s);
ABCExportContext context = ABCExportContext::current();
if (context && context.parmTrimResult())
{
ret = strLRTrim(ret);
}
return ret;
}
}
The caller opens it with using (ABCExportContext context = new ABCExportContext()) { context.parmTrimResult(true); … }, and next may stand inside such a using block.
insert_recordset, update_recordset and delete_from skip a wrapper of insert / update / delete when the table itself doesn't override that method. The statement stays one set-based SQL statement. When the table overrides the method, the statement runs row by row and the wrappers run for every row.Inserting, Inserted, …) makes those statements run row by row and is called per row, unless the caller sets skipEvents(true). skipDataMethods(true) alone doesn't stop the events. So a handler on a large table has a cost for every set-based statement on it.doInsert(), doUpdate() and doDelete() run neither wrappers nor data events.Before you rely on a table wrapper, find out how the rows you care about are written.
Assign the field before next insert() / next update(), or in Inserting / Updating. A value assigned after next, in Inserted / Updated, or in a post handler isn't saved.
orig() during an update| Place | orig() holds |
|---|---|
Wrapper before next update(), Updating event, pre handler | Old values |
Updated event | Old values |
Wrapper after next update(), post handler | New values |
Read old values before next, or in the Updated event.
| Place | This fails it | This doesn't |
|---|---|---|
Wrapper of validateWrite | ret = next validateWrite(); ret = ret && checkFailed("…"); and return ret | |
ValidatingWrite data event | args.parmValidateResult(false); ValidatedWrite is then not raised | |
ValidatedWrite data event | args.parmValidateResult(false) | checkFailed("…") alone |
| Post handler | _args.setReturnValue(_args.getReturnValue() && checkFailed("…")) | checkFailed("…") alone |
The validating and validated data events (…Write, …Delete) carry ValidateEventArgs.
<DataMethod>SalesTable_ContosoCustomizations_Extension.abcDisplayCustGroupName</DataMethod>. The plain method name is error DataMethodNotFoundOnDataSource, and only a full build reports it. A display method on a form data source extension class is bound the same way.public static and is bound with ::: <ComputedFieldMethod>SalesOrderHeaderV2Entity_ContosoCustomizations_Extension::abcComputeTotalWeight</ComputedFieldMethod>.[SysClientCacheDataMethod] takes _updateOnWrite, default true: the cached value is already refreshed on write without an argument.A query is extended declaratively (AxQuerySimpleExtension: data sources and ranges), not by an extension class.
staticDelegateStr(C, name) and to an instance delegate with delegateStr(C, name). The other way round is a compile error.delegate void <name>. Delegates often sit on companion classes (FinancialDimensionValueEntityDelegates, SRSPrintDestinationSettingsDelegates).EventHandlerResult only inside your own case. Don't test hasResult() to decide, and never answer in a default: branch.EventHandlerRejectResult: call reject() or checkFailed("Message text").XppPrePostArgs.getArgNum(n) is 1-based. Prefer getArg(identifierStr(_name)).FormControlCancelEventArgs: cancel(true) to cancel; the getter is cancelled().Clicked or ValidatingDelete handler, throw error("…") / throw warning("…") works.final classes with public static void methods. A static handler placed in an [ExtensionOf] class gives warning EventHandlerInClassExtension.<Element>_on<Event> for data and form events (InventItemBarcode_onUpdating), <Class>_<Pre|Post>_<method> for pre/post handlers.[SuppressBPWarning('BPParameterNotUsed', 'Parameter required by the event interface')].Form extensions (AxFormExtension) hold no code; all code goes in AxClass files. The standard form needs no recompiling.
Read references/forms.md before you write form code. It covers how to reach form members from each extension level, adding a control at run time, per-form state for a handler class, and the arguments of registerOverrideMethod. The rules below apply to every form change.
formDataSourceStr extension. In a formStr extension it is a compile error with next, and without next it compiles as a new method that nothing calls.create: public void create(boolean _append).public void performFormLookup(xFormRun _form, FormControl _formControl).written() of a data source. It compiles and is never called on save. Subscribe to the Written event.init: Initializing is raised inside super(), before the data sources are initialised. Initialized handlers run before the code after next init() and before the form's own code after super(). Code that must run last goes after next init().next clicked() → Clicking → Clicked → wrapper code after next. Use FormControlEventType::Clicking to run before a click without CoC.formStr extension works and runs on the form instance. Prefer an init() wrapper when you need form state.ValidatingWrite or ValidatedWrite handler, cast the args to FormDataSourceCancelEventArgs and call cancel(true). Both block the save.cancel(checkFailed("…")) shows the message and saves, because checkFailed returns false. Write checkFailed("…"); args.cancel(true);, or args.cancel(args.cancel() || shouldCancel).Writing can't cancel.Take the first row that fits. The recipes are in references/lookups.md; read it before you write the lookup.
| # | Situation | Technique |
|---|---|---|
| 1 | A relation or EDT reference gives the right lookup | No code. |
| 2 | One control, standard or added by your form extension | Control Lookup event handler that ends with CancelSuperCall(). |
| 3 | A data source field shown in several controls, or the lookup needs form state | registerOverrideMethod(methodStr(FormDataObject, lookup), …) on the field object in init(). |
| 4 | RecId foreign key in a reference group | lookupReference on the field object and resolveReference on the reference group control. |
| 5 | Dialog field | DialogField.registerOverrideMethod(methodStr(FormStringControl, lookup), …) (references/dialogs.md). |
| 6 | Keep the standard lookup, run it differently | CoC on the data field, next inside. |
| 7 | The lookup is built by a table or class method | CoC on that method. It changes every form that uses it, so guard on the caller. If the method is [Replaceable], the wrapper may skip next. |
| 8 | Several values in one control | SysLookupMultiSelectCtrl. |
references/dialogs.md has the recipe for a field that your extension adds to a standard RunBase dialog, and the rules for SysOperation contracts and UI builders. In both, register overrides after the dialog exists (dialogPostRun, postBuild, postRun) and name the target class, not the extension class, in methodStr(…).
You will meet these in existing project code. Don't copy them, and report them in a review.
| Pattern | Write instead |
|---|---|
Lookup handler with no CancelSuperCall() | Cancel on the path that showed a lookup. |
cancel(checkFailed(…)) in a form data source handler | The record is saved. checkFailed(…); args.cancel(true); |
Post handler or ValidatedWrite handler that only calls checkFailed | Write the result back: setReturnValue(…), parmValidateResult(false). |
Field assigned after next insert() / next update() or in an -ed event | Assign it before next. |
resolveReference registered on the field object | Register it on the reference group control. |
Wrapper or override of data source written() | Written event. |
Table insert / update / delete wrapper expected to cover set-based statements | Check whether the table overrides the method (When your code is not called). |
Conditional next in write / validateWrite of a data source added by a form extension | Legal there only. Check that no path drops the save by mistake. |
controlName("literal"), dataSource(<number>) | formControlStr, formDataSourceStr. |
[ExtensionOf] class that holds only static handlers | A plain handler class. |
| Two extension classes for one target | One class per target and concern. |
Handler named …_Post_insert that carries [PreHandlerFor] | Re-read the attribute when you copy a handler; name it after what it is. |
Commented-out /* [DataEventHandler(…)] */ blocks | Dead code. Don't revive it without checking the fields it uses. |
Review checklist:
final, name ends in _Extension, one [ExtensionOf] that matches the level, no other extension class for the target.static kept, next once and unconditional, its result captured and returned.next insert() / next update().public static void, the right event tense, the failure written back (setReturnValue, parmValidateResult, cancel(true)).Lookup handler cancels the super call; a delegate subscriber answers only its case.using.These come from Microsoft's documentation, standard source, or production code that compiles. Verify them when the result depends on them.
tableStr(<Entity>), wrapping entity methods.:: binding.unchecked (Uncheck::XDS): it compiles and runs; its effect on a policy wasn't checked.[SysClientCacheDataMethod]: the default was read from the attribute's source.EventHandlerResult and EventHandlerRejectResult, the cancelled() getter, and throwing from a Clicked or ValidatingDelete handler.jumpRef registration and the cross-company lookup in the reference files.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub trudax/d365fo-xpp-skills --plugin trud-d365fo-xpp5 skills in this plugin
/d365-xpp-compileSet up the task's Visual Studio project and git branch, then build a Dynamics 365 Finance & Operations (D365 F&O, AX7) X++ project (.rnrproj) from the command line the way Visual Studio does on a development VM (CHE or VHD) - compile its package with xppc into PackagesLocalDirectory, compile labels, sync changed tables and data entities, restart the AOS so the change can be tested - and analyse the compile errors. Use this at the start of every task that will create or modify X++ / AOT elements (AxClass, AxTable, AxForm, table/form/class extensions, EDTs, enums, menu items, data entities, security, labels), before the first edit - to create or find the task's project and branch - and after the changes - add the changed elements to the project, build, and fix errors until the build is clean, without waiting to be asked. Also use when the user says "build/compile the project", "deploy it so I can test", "check that it compiles", "run xppc", or pastes X++ compiler errors./d365-xpp-conventionsConventions for creating Dynamics 365 Finance & Operations (D365 F&O, AX7) X++ elements as metadata XML - new tables and table fields, EDTs, table relations, setup forms (simple list, list and details with a tabular grid), RunBase dialog and batch classes, table/form/enum extensions, Chain of Command and event handler classes, menu items and security privileges. Use this before writing the XML whenever you create a table, add fields to a table or table extension, create a form, an extension or extension class, a RunBase/RunBaseBatch class or other periodic operation, a menu item or a privilege - even when the user only says "create a table for X", "add a field", or "make a job that updates Y"./d365-xpp-trace-parserRead a Dynamics 365 Finance & Operations (D365 F&O, AX7) trace that was imported into a Trace Parser SQL database and link it to the X++ code - which SQL statement wrote a value, the actual bind values of every insert and update, the call stack of a statement, and which methods ran in what order. Use this when the user has captured a trace (Settings > Trace, Trace Parser, an .etl file) and asks why a field got a value, which code created or changed a record, what a batch job or wave run did, or to "read the trace", "the trace is imported into the database", "find in the trace where X was set", "link the trace to the X++ logic"./d365-xpp-xrefFind where a Dynamics 365 Finance & Operations (D365 F&O, AX7) X++ element is used by querying the cross-reference database (DYNAMICSXREFDB) instead of searching source files. Use this when the user asks "where is X used", "who calls method Y", "which classes use SalesLine.SalesPrice", "find references", "find all usages", "what extends/implements class Z", "which methods have attribute A", or wants an impact analysis before changing a table field, method, EDT, enum, or class - especially across large models such as ApplicationSuite, where grepping XML is slow and token-heavy. Also use it before writing a Chain of Command extension, to find the existing [ExtensionOf] class of that class, table or form in the user's model and add the new method there instead of creating another extension class.