Comentality.Events2Code 1.1.1

dotnet add package Comentality.Events2Code --version 1.1.1
                    
NuGet\Install-Package Comentality.Events2Code -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Comentality.Events2Code" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Comentality.Events2Code" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Comentality.Events2Code" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Comentality.Events2Code --version 1.1.1
                    
#r "nuget: Comentality.Events2Code, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Comentality.Events2Code@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Comentality.Events2Code&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Comentality.Events2Code&version=1.1.1
                    
Install as a Cake Tool

alternate text is missing from this package README image Events2Code

NuGet

An XrmToolBox tool that converts Dynamics 365 form event handler registrations made in the form designer UI into equivalent JavaScript code — and unregisters them from the form.

Registering event handlers through the form designer (Form Properties → Event Handlers) is tedious and hides your form logic in form XML, where it cannot be reviewed or diffed with the code it calls. The modern approach is to register everything from a single OnLoad bootstrap using the Client API (addOnChange, addOnSave, addTabStateChange, …). Events2Code automates the migration.

Its home is comentality.com/tools; this repository is where it is built.

Events2Code showing a form's handlers and the generated bootstrap

Install

  • XrmToolBox Tool Library — search for Events2Code and install it.
  • Manually — download Events2Code.dll from the latest release, copy it into your XrmToolBox Plugins folder, and restart XrmToolBox.

Needs XrmToolBox 1.2025.7+, .NET Framework 4.8, and a connection whose user can update forms and publish customizations.

What it does

  • Browse forms — connect via XrmToolBox, pick a table, and see all Main and Quick Create forms

  • List registrations — every UI-registered handler with event type, target, function, library, parameters, and enabled state

  • Generate JavaScript — one OnLoad bootstrap that registers the checked handlers programmatically:

    Designer registration Generated call
    Form OnSave formContext.data.entity.addOnSave(...)
    Attribute OnChange formContext.getAttribute(...)?.addOnChange(...)
    Tab state change formContext.ui.tabs.get(...)?.addTabStateChange(...)
    Subgrid OnLoad formContext.getControl(...)?.addOnLoad(...)
    Form OnLoad called directly from the bootstrap

    Lookups are guarded with ?. so a field, tab, or grid missing from the current form variant is skipped instead of throwing and killing every registration after it. This makes the output ES2020 — fine for Unified Interface, but check any minifier or ESLint config pinned to ES5.

  • Handles designer quirks — extra handler parameters and the "pass execution context" flag are preserved via wrapper closures; disabled handlers are emitted commented out

  • Unregister UI handlers — removes the checked handlers from the form XML, registers your bootstrap on form OnLoad, adds its web resource to the form libraries, updates the form, and publishes

  • Safety first — the original form XML is backed up to Documents\Events2Code\backups before any change, internal Dynamics handlers are never touched, and managed forms trigger a warning

Workflow

  1. Load tables, pick a table, pick a form.
  2. Review the handler grid; uncheck anything you want to leave as is.
  3. Set the bootstrap function name (e.g. MyOrg.FormEvents.onLoad) and the web resource name it will live in.
  4. Generate Code, then save the JavaScript into that web resource (create/update it in your solution) and publish it.
  5. Unregister UI Handlers — the tool strips the old registrations, wires up the bootstrap OnLoad, and publishes the table.

The order matters: upload the web resource before unregistering, or the form will briefly have no working scripts.

The layout follows the window, so it stays usable docked narrow:

Events2Code in a narrow window

Documentation

Notes

  • Form OnLoad itself cannot be registered from code, so exactly one UI registration remains: the bootstrap.
  • Events with no programmatic registration API (e.g. business process flow events) are listed but left untouched on the form.
  • A subgrid on a collapsed or non-default tab does not exist yet at form OnLoad, so its registration is skipped at runtime; move that one into the tab's state change handler by hand.

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 43 11/4/2026
1.1.0 130 10/22/2026
1.0.0 238 8/18/2026

v1.1.1
- An About button on the toolbar now shows which build you have and where to report what is wrong.
Full changelog, with screenshots: https://github.com/comentality/xrm-events-2-code/releases/tag/v1.1.1

v1.1.0
- Changing the connection now clears the old environment from the window, so no write can land in the wrong one.
- On a slow connection the forms list and handler grid always show what you clicked last, and the buttons wait for it.
- Loading tables, forms and a form's XML can now be cancelled from the Cancel button on the loading panel.
- A failed load now stays on the status line, which also says what is still loading instead of counting too early.
- Closing the tab mid-load no longer pops up an error later, and a save to a dead share no longer freezes the window.

v1.0.0
- Browse tables and their Main and Quick Create forms over an XrmToolBox connection, with a filter on display or logical name.
- List every event handler a form registers through the designer, with its event, target, function, library and enabled state.
- Generate a single OnLoad bootstrap function that registers the checked handlers through the Client API.
- Designer quirks are preserved: extra parameters and the "pass execution context" flag are re-emitted through wrapper closures.
- Copy the generated code to the clipboard or save it to a .js file.
- Unregister the checked handlers: they leave the form XML, the bootstrap is registered on form OnLoad, and the table is published.
- Back up the form XML to Documents\Events2Code\backups before any change, and warn on managed forms.
- The generated-code preview is syntax highlighted.