bc-attachments-generator
Skill28 starsChanged 7 months agoMITView on GitHub
Implements standard document attachments, links, and notes on custom Business Central tables. Creates setup fields for visibility control, extends Attachment Document Type enum, generates event subscribers (OnAfterGetRecRefFail, OnAfterOpenForRecRef, OnAfterInitFieldsFromRecRef) in attachment management codeunit, adds table lifecycle triggers for orphan prevention on delete/rename, and extends card and list pages with the modern Doc. Attachment List Factbox. Handles SubPageLink configuration, control ID mapping for Links (Control1900383207) and Notes (Control1905767507) factboxes. Use when adding attachments to custom tables, implementing document management, enabling factboxes for documents, creating attachment integration on entities, adding links and notes to records, or preventing orphan attachment records on table operations.
In this repository38 other files it gives its agents.
- bc-agent-instructions-debuggerSkill
- bc-al-bug-fixSkill
- bc-al-code-reviewerSkill
- bc-al-project-contextSkill
- bc-api-page-generatorSkill
- bc-api-query-generatorSkill
- bc-approval-workflow-generatorSkill
- skill-batch-processingSkill
- bc-business-events-generatorSkill
- bc-cds-page-generatorSkill
- bc-dataverse-entity-generatorSkill
- bc-dataverse-mapping-generatorSkill
- bc-field-propagationSkill
- bc-install-codeunit-generatorSkill
- bc-isolated-storage-generatorSkill
- bc-job-queueSkill
- bc-manifest-handoff-generatorSkill
- bc-matrix-page-generatorSkill
- bc-number-series-generatorSkill
- bc-pricing-refactorSkill
- bc-report-selection-generatorSkill
- bc-reportsSkill
- bc-setup-table-generatorSkill
- bc-setup-wizard-generatorSkill
- bc-table-dimensions-generatorSkill
- bc-telemetry-generatorSkill
- bc-test-codeunit-generatorSkill
- bc-upgrade-codeunit-generatorSkill
- documentation-bc-analysis-generatorSkill
- documentation-bc-architecture-generatorSkill
- documentation-bc-ccn-generatorSkill
- documentation-bc-md-to-docx-converterSkill
- documentation-bc-phase-plan-generatorSkill
- documentation-bc-release-note-generatorSkill
- documentation-bc-technical-spec-generatorSkill
- documentation-bc-user-story-generatorSkill
- onprem-remote-deploySkill
- skill-contribution-assistantSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 10 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 36
Add 3 boolean fields to setup table:
- Distinctive: line 47
Add 3 fields to setup page layout in General group.
- Distinctive: line 71
Create codeunit with 3 event subscribers + 5 procedures.
- Distinctive: line 101
Add factboxes section with:
- Very specific: line 108
Add OnOpenPage() trigger to set visibility variables.
- Distinctive: line 120
Control ID Note: If modify fails (e.g., "Control not found"), inspect base page to find actual IDs.
- Distinctive: line 130
Add to permission set:
- Distinctive: line 139
Delete record → verify attachments deleted
- Very specific: line 147
Check setup page: ensure "Enable Attachments/Links/Notes" checked
- Very specific: line 148
Verify OnOpenPage() trigger runs and sets variables
- Distinctive: line 152
Verify enum extension exists and builds first
- Very specific: line 153
Check SubPageLink includes correct "Table ID" and "No." field
- Very specific: line 167
Add to "Doc. Attachment List Factbox" part
- Distinctive: line 171
When adding attachments to multiple tables in one extension, use case statements in all event subscribers and procedures.
- Distinctive: line 180
Use Links factbox for SharePoint URLs
≈ “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
BC Attachments, Links & Notes Generator
Automates BC standard document attachment functionality on custom tables.
Overview
Generates complete attachment, link, and notes implementation for custom BC tables following Microsoft patterns. Creates 3 event subscribers, lifecycle triggers, modern factbox configuration, and setup controls.
Complete code templates available in: references/code-templates.md
Prerequisites
- AL workspace with custom table
- Setup table (or will create one)
- Card and List pages for entity
Workflow
Step 1: Gather Information
Collect from user:
- Entity name (e.g., "Statistical Account")
- Table name and ID
- Prefix (e.g., "BCS")
- Primary key field (usually "No.")
- Setup table name
- Card and list page names
Step 2: Update Setup Table
Add 3 boolean fields to setup table:
"Enable Attachments"(InitValue = true)"Enable Links"(InitValue = true)"Enable Notes"(InitValue = true)
Location: src/Table/[Prefix][SetupName].Table.al
See code-templates.md for complete code.
Step 3: Update Setup Page
Add 3 fields to setup page layout in General group.
Location: src/Page/[Prefix][SetupName].Page.al
See code-templates.md for complete code.
Step 4: Create Enum Extension
Extend "Attachment Document Type" enum with custom value.
Location: src/Enum Extension/[Prefix]AttachmentDocType.EnumExt.al
enumextension [ID] "[Prefix] Attachment Doc Type" extends "Attachment Document Type"
{
value([ID]; [Prefix][Entity]) // Remove spaces: "Statistical Account" → "BCSStatisticalAccount"
{
Caption = '[Entity]';
}
}Step 5: Create Attachment Management Codeunit
Create codeunit with 3 event subscribers + 5 procedures.
Location: src/Codeunit/[Prefix]AttachmentManagement.Codeunit.al
Event Subscribers:
OnAfterGetRecRefFail- Handle record reference resolution for attachment factbox (Page::"Doc. Attachment List Factbox")OnAfterOpenForRecRef- Filter attachments when opening details (Page::"Document Attachment Details")OnAfterInitFieldsFromRecRef- Initialize attachment from record (Table::"Document Attachment")
Procedures:
EntityEnabledAttachments(TableId)- Check if attachments enabledEntityEnabledLinks(TableId)- Check if links enabledEntityEnabledNotes(TableId)- Check if notes enabledDeleteRelatedDocumentAttachments(No)- Delete attachments on record deleteCopyRelatedDocumentAttachments(OldNo, NewNo)- Copy attachments on rename
See code-templates.md for complete code.
Step 6: Add Table Lifecycle Triggers
Extend table with:
OnBeforeRename()- Copy attachments to new No., delete old onesOnBeforeDelete()- Delete related attachments to prevent orphans
Location: Update existing table extension
See code-templates.md for complete code.
Step 7: Extend Card Page
Add factboxes section with:
- Modern factbox:
"Doc. Attachment List Factbox"(UpdatePropagation = Both) - Modify Links factbox:
Control1900383207 - Modify Notes factbox:
Control1905767507
Note: The legacy
"Document Attachment Factbox"is fully deprecated and must NOT be included.
Add OnOpenPage() trigger to set visibility variables.
Location: src/Page Extension/[Prefix][Entity]Card.PageExt.al
SubPageLink configuration:
SubPageLink = "Table ID" = const(Database::"[Base Table]"),
"No." = field("No.");See code-templates.md for complete code.
Control ID Note: If modify fails (e.g., "Control not found"), inspect base page to find actual IDs. They may vary between BC versions.
Step 8: Extend List Page
Repeat Step 7 for list page.
Location: src/Page Extension/[Prefix][Entity]List.PageExt.al
Step 9: Update Permissions
Add to permission set:
codeunit "[Prefix] Attachment Management" = X;Step 10: Test
Critical tests:
- Upload attachment → verify appears in factbox
- Delete record → verify attachments deleted
- Rename record → verify attachments follow (copied to new No.)
- Navigate between records → verify factbox refreshes
- Toggle setup fields → verify factboxes hide/show
Troubleshooting
Factboxes Not Appearing
- Check setup page: ensure "Enable Attachments/Links/Notes" checked
- Verify
OnOpenPage()trigger runs and sets variables - Confirm
DATABASE::"[Table]"matches exactly (case-sensitive)
Attachments Not Filtering
- Verify enum extension exists and builds first
- Check
SubPageLinkincludes correct"Table ID"and"No."field - Confirm
OnAfterInitFieldsFromRecRefsets"Document Type"correctly
Orphan Attachments After Delete/Rename
- Missing
OnBeforeDeletetrigger → Add and callDeleteRelatedDocumentAttachments() - Missing
OnBeforeRenametrigger → AddRenameAttachments()procedure
Links/Notes Factbox Visibility Not Working
- Wrong control IDs → Inspect base page to find actual IDs
- Common IDs:
1900383207(Links),1905767507(Notes) - Base page may not have these factboxes
Factbox Not Refreshing on Navigation
- Missing
UpdatePropagation = Bothon modern factbox - Add to
"Doc. Attachment List Factbox"part
Multi-Entity Pattern
When adding attachments to multiple tables in one extension, use case statements in all event subscribers and procedures.
See code-templates.md for complete example.
Storage Best Practice
BC has database storage limits. Recommend:
- Small files in BC attachments (< 1 MB)
- Large files in SharePoint/OneDrive
- Use Links factbox for SharePoint URLs
Quick Reference
Required Objects:
- Setup fields (3 booleans)
- Enum extension
- Attachment management codeunit (3 event subscribers, 5 procedures)
- Table triggers (OnBeforeDelete, OnBeforeRename)
- Page factboxes (card and list)
Event Subscribers:
OnBeforeDrillDown(obsolete factbox)OnAfterOpenForRecRef(details page)OnAfterInitFieldsFromRecRef(initialization)
Factbox Control IDs:
- Links:
Control1900383207 - Notes:
Control1905767507 - May vary by BC version
Real-world example: BC Scout Statistical Accounts
- Rename record → verify attachments follow (copied to new No.)
- Navigate between records → verify factbox refreshes
- Toggle setup fields → verify factboxes hide/show
Troubleshooting
Factboxes Not Appearing
- Check setup page: ensure "Enable Attachments/Links/Notes" checked
- Verify
OnOpenPage()trigger runs and sets variables - Confirm
DATABASE::"[Table]"matches exactly (case-sensitive)
Attachments Not Filtering
- Verify enum extension exists and builds first
- Check
SubPageLinkincludes correct"Table ID"and"No."field - Confirm
OnAfterInitFieldsFromRecRefsets"Document Type"correctly
Orphan Attachments After Delete/Rename
- Missing
OnBeforeDeletetrigger → Add and callDeleteRelatedDocumentAttachments() - Missing
OnBeforeRenametrigger → AddRenameAttachments()procedure
Links/Notes Factbox Visibility Not Working
- Wrong control IDs → Inspect base page to find actual IDs
- Common IDs:
1900383207(Links),1905767507(Notes) - Base page may not have these factboxes
Factbox Not Refreshing on Navigation
- Missing
UpdatePropagation = Bothon modern factbox - Add to
"Doc. Attachment List Factbox"part
Multi-Entity Pattern
When adding attachments to multiple tables in one extension, use case statements in all event subscribers and procedures.
See code-templates.md for complete example.
Storage Best Practice
BC has database storage limits. Recommend:
- Small files in BC attachments (< 1 MB)
- Large files in SharePoint/OneDrive
- Use Links factbox for SharePoint URLs
Quick Reference
Required Objects:
- Setup fields (3 booleans)
- Enum extension
- Attachment management codeunit (3 event subscribers, 5 procedures)
- Table triggers (OnBeforeDelete, OnBeforeRename)
- Page factboxes (card and list)
Event Subscribers:
OnBeforeDrillDown(obsolete factbox)OnAfterOpenForRecRef(details page)OnAfterInitFieldsFromRecRef(initialization)
Factbox Control IDs:
- Links:
Control1900383207 - Notes:
Control1905767507 - May vary by BC version
Real-world example: BC Scout Statistical Accounts
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.

