binding-event-subscribers
Skill1 starsChanged 9 months agoMITView on GitHub
Turns event subscribers on and off dynamically using BindSubscription() and UnbindSubscription() with EventSubscriberInstance = Manual for conditional event handling. Use when disabling subscribers during batch jobs, enabling page-scoped validation, implementing feature toggles via setup, turning off event handlers for performance, or controlling dynamic event execution at runtime.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- authenticating-with-oauthSkill
- building-cue-rolecentersSkill
- consuming-bc-standard-apiSkill
- controlling-al-accessSkill
- creating-bc-custom-apiSkill
- handling-bc-filesSkill
- implementing-al-interfacesSkill
- implementing-telemetrySkill
- integrating-azure-servicesSkill
- optimizing-bc-performanceSkill
- writing-git-commitsSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Note: Default to StaticAutomatic.
- Distinctive: line 91
⚠️ Do NOT use Manual for critical business logic that must never be missed.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Skill: AL Event Binding
Validation Gates
- After Step 1: Manual codeunit compiles, subscribers don't fire without binding
- After Step 2: BindSubscription activates subscriber, events fire correctly
- Final: UnbindSubscription deactivates, no events fire after unbind
Note: Default to StaticAutomatic. Use Manual only for conditional/performance scenarios. Binding is session-specific.
Procedure
Step 1: Create Manual Subscriber Codeunit
codeunit <ID> "<PREFIX> <Entity> Subscribers"
{
EventSubscriberInstance = Manual;
[EventSubscriber(ObjectType::Table, Database::<SourceTable>, 'OnAfterValidateEvent', '<FieldName>', false, false)]
local procedure OnValidate<FieldName>(var Rec: Record <SourceTable>)
begin
// Your validation logic here
if StrLen(Rec.<FieldName>) < 3 then
Error('<FieldName> must be at least 3 characters');
end;
}Step 2: Bind in Context (Page/Codeunit)
pageextension <ID> "<PREFIX> <Entity> Card Ext" extends "<SourcePageName>"
{
var
EntitySubscribers: Codeunit "<PREFIX> <Entity> Subscribers";
trigger OnOpenPage()
begin
BindSubscription(EntitySubscribers);
end;
trigger OnClosePage()
begin
UnbindSubscription(EntitySubscribers);
end;
}Common Patterns
Conditional via Setup
procedure ProcessDocument(var SourceRecord: Record <SourceTable>)
var
AdvancedValidation: Codeunit "<PREFIX> Advanced Validation";
Setup: Record "<PREFIX> Setup";
begin
if Setup.Get() and Setup."Enable Advanced Validation" then
BindSubscription(AdvancedValidation);
Codeunit.Run(Codeunit::<ProcessingCodeunit>, SourceRecord);
// Auto-unbinds when procedure ends
end;Batch Job Optimization
UI subscribers bound only in pages, not in job queue codeunits:
- Page:
OnOpenPage→BindSubscription(UINotifications) - Job Queue: No binding → no UI overhead
Important Notes
Binding behavior:
- Session-specific (Session A binding doesn't affect Session B)
- Auto-dissolves when codeunit instance goes out of scope
- Cannot call Bind/Unbind on
StaticAutomaticcodeunits (runtime error)
Stale metadata: Recompiling bound codeunit shows error "subscriber is stale" - only during development, not production.
⚠️ Do NOT use Manual for critical business logic that must never be missed.
External Documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

