bc-code-intelligence-mcp 1.5.6 → 1.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +165 -419
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/layers/embedded-layer.js +29 -29
- package/dist/layers/project-layer.js +33 -33
- package/dist/sdk/bc-code-intel-client.d.ts.map +1 -1
- package/dist/sdk/bc-code-intel-client.js +1 -1
- package/dist/sdk/bc-code-intel-client.js.map +1 -1
- package/dist/services/knowledge-service.d.ts +1 -1
- package/dist/services/knowledge-service.d.ts.map +1 -1
- package/dist/services/knowledge-service.js +71 -3
- package/dist/services/knowledge-service.js.map +1 -1
- package/dist/services/methodology-service.js +14 -14
- package/dist/services/multi-content-layer-service.d.ts +15 -0
- package/dist/services/multi-content-layer-service.d.ts.map +1 -1
- package/dist/services/multi-content-layer-service.js +62 -0
- package/dist/services/multi-content-layer-service.js.map +1 -1
- package/dist/streamlined-handlers.d.ts +0 -7
- package/dist/streamlined-handlers.d.ts.map +1 -1
- package/dist/streamlined-handlers.js +80 -60
- package/dist/streamlined-handlers.js.map +1 -1
- package/dist/tools/core-tools.d.ts.map +1 -1
- package/dist/tools/core-tools.js +4 -0
- package/dist/tools/core-tools.js.map +1 -1
- package/dist/tools/onboarding-tools.d.ts +8 -0
- package/dist/tools/onboarding-tools.d.ts.map +1 -1
- package/dist/tools/onboarding-tools.js +111 -1
- package/dist/tools/onboarding-tools.js.map +1 -1
- package/dist/types/bc-knowledge.d.ts +4 -4
- package/embedded-knowledge/.github/ISSUE_TEMPLATE/bug-report.md +23 -23
- package/embedded-knowledge/.github/ISSUE_TEMPLATE/content-improvement.md +23 -23
- package/embedded-knowledge/.github/ISSUE_TEMPLATE/knowledge-request.md +29 -29
- package/embedded-knowledge/AGENTS.md +177 -177
- package/embedded-knowledge/CONTRIBUTING.md +57 -57
- package/embedded-knowledge/LICENSE +20 -20
- package/embedded-knowledge/README.md +31 -31
- package/embedded-knowledge/domains/alex-architect/samples/testability-design-patterns.md +223 -0
- package/embedded-knowledge/domains/alex-architect/testability-design-patterns.md +77 -0
- package/embedded-knowledge/domains/casey-copilot/long-running-session-instructions.md +263 -0
- package/embedded-knowledge/domains/casey-copilot/samples/long-running-session-instructions.md +323 -0
- package/embedded-knowledge/domains/eva-errors/codeunit-run-pattern.md +159 -0
- package/embedded-knowledge/domains/eva-errors/samples/codeunit-run-pattern.md +239 -0
- package/embedded-knowledge/domains/eva-errors/samples/try-function-usage.md +195 -0
- package/embedded-knowledge/domains/eva-errors/try-function-usage.md +129 -0
- package/embedded-knowledge/domains/morgan-market/partner-readiness-analysis.md +201 -0
- package/embedded-knowledge/domains/morgan-market/samples/partner-readiness-checklist.md +288 -0
- package/embedded-knowledge/domains/quinn-tester/isolation-testing-patterns.md +82 -0
- package/embedded-knowledge/domains/quinn-tester/samples/isolation-testing-patterns.md +424 -0
- package/embedded-knowledge/domains/roger-reviewer/samples/testability-code-smells.md +256 -0
- package/embedded-knowledge/domains/roger-reviewer/testability-code-smells.md +67 -0
- package/embedded-knowledge/domains/shared/al-file-naming-conventions.md +145 -145
- package/embedded-knowledge/methodologies/index.json +80 -80
- package/embedded-knowledge/methodologies/phases/analysis-full.md +207 -207
- package/embedded-knowledge/methodologies/phases/analysis-quick.md +43 -43
- package/embedded-knowledge/methodologies/phases/analysis.md +181 -181
- package/embedded-knowledge/methodologies/phases/execution-validation-full.md +173 -173
- package/embedded-knowledge/methodologies/phases/execution-validation-quick.md +30 -30
- package/embedded-knowledge/methodologies/phases/execution-validation.md +173 -173
- package/embedded-knowledge/methodologies/phases/performance-full.md +210 -210
- package/embedded-knowledge/methodologies/phases/performance-quick.md +31 -31
- package/embedded-knowledge/methodologies/phases/performance.md +210 -210
- package/embedded-knowledge/methodologies/phases/verification-full.md +161 -161
- package/embedded-knowledge/methodologies/phases/verification-quick.md +47 -47
- package/embedded-knowledge/methodologies/phases/verification.md +145 -145
- package/embedded-knowledge/methodologies/workflow-enforcement.md +141 -141
- package/embedded-knowledge/methodologies/workflows/code-review-workflow.md +98 -98
- package/package.json +81 -81
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# Long-Running Session Instruction Examples
|
|
2
|
+
|
|
3
|
+
## Complete Project Instructions Template
|
|
4
|
+
|
|
5
|
+
```markdown
|
|
6
|
+
# Project: Customer Integration Extension
|
|
7
|
+
|
|
8
|
+
## Project Context
|
|
9
|
+
This BC extension syncs customer data with ExternalCRM system.
|
|
10
|
+
- BC Version: 24.0
|
|
11
|
+
- Extension ID: 70100000-70100099
|
|
12
|
+
- Dependencies: Base Application, System Application
|
|
13
|
+
|
|
14
|
+
## Environment Setup
|
|
15
|
+
- Workspace: /src contains AL code
|
|
16
|
+
- Tests: /test contains test codeunits
|
|
17
|
+
- Config: app.json, launch.json configured for dev container
|
|
18
|
+
|
|
19
|
+
## Getting Started Each Session
|
|
20
|
+
|
|
21
|
+
Before any coding work:
|
|
22
|
+
1. Run `pwd` to confirm you're in the project root
|
|
23
|
+
2. Read PROGRESS.md for the latest session summary
|
|
24
|
+
3. Read FEATURES.json to see what's complete and what's pending
|
|
25
|
+
4. Check `git log --oneline -10` for recent commits
|
|
26
|
+
5. Compile the extension (Ctrl+Shift+B) to verify baseline
|
|
27
|
+
6. Run tests to confirm nothing is broken
|
|
28
|
+
|
|
29
|
+
If the project is in a broken state, fix it BEFORE implementing new features.
|
|
30
|
+
|
|
31
|
+
## Feature Requirements
|
|
32
|
+
|
|
33
|
+
See FEATURES.json for the structured list. High-level features:
|
|
34
|
+
1. Customer Lookup - Find BC customer by external ID
|
|
35
|
+
2. Customer Create - Create BC customer from external data
|
|
36
|
+
3. Customer Update - Sync specific fields from external system
|
|
37
|
+
4. Error Logging - Log failures to Integration Log table
|
|
38
|
+
5. Retry Mechanism - Automatic retry of failed syncs
|
|
39
|
+
6. Manual Sync - Page action to trigger sync on demand
|
|
40
|
+
|
|
41
|
+
## Working Pattern
|
|
42
|
+
|
|
43
|
+
Each session, follow this pattern:
|
|
44
|
+
1. Complete the orientation steps above
|
|
45
|
+
2. Choose ONE incomplete feature from FEATURES.json
|
|
46
|
+
3. Implement that feature incrementally:
|
|
47
|
+
- Table changes first (if needed)
|
|
48
|
+
- Codeunit logic second
|
|
49
|
+
- Page updates third
|
|
50
|
+
- Tests alongside each object
|
|
51
|
+
4. Verify the feature works end-to-end
|
|
52
|
+
5. Commit with message: "feat: [Feature Name] - [Brief Description]"
|
|
53
|
+
6. Update PROGRESS.md with session summary
|
|
54
|
+
7. Update FEATURES.json to mark feature as passing
|
|
55
|
+
8. STOP - do not start another feature
|
|
56
|
+
|
|
57
|
+
## Verification Requirements
|
|
58
|
+
|
|
59
|
+
A feature is NOT complete until:
|
|
60
|
+
- [ ] Extension compiles without errors or warnings
|
|
61
|
+
- [ ] Unit tests pass for new code
|
|
62
|
+
- [ ] Integration tests verify end-to-end behavior
|
|
63
|
+
- [ ] Manual test confirms expected behavior
|
|
64
|
+
- [ ] Existing tests still pass (no regressions)
|
|
65
|
+
|
|
66
|
+
Do NOT mark features passing based on code review alone.
|
|
67
|
+
|
|
68
|
+
## End of Session Checklist
|
|
69
|
+
|
|
70
|
+
Before ending any session:
|
|
71
|
+
- [ ] Extension compiles cleanly
|
|
72
|
+
- [ ] All tests pass
|
|
73
|
+
- [ ] Changes committed with descriptive message
|
|
74
|
+
- [ ] PROGRESS.md updated
|
|
75
|
+
- [ ] FEATURES.json updated if feature completed
|
|
76
|
+
- [ ] No uncommitted work-in-progress
|
|
77
|
+
|
|
78
|
+
It is unacceptable to leave the codebase in a non-compiling state.
|
|
79
|
+
|
|
80
|
+
## Code Standards
|
|
81
|
+
|
|
82
|
+
Follow these BC/AL standards:
|
|
83
|
+
- Use meaningful names following BC conventions
|
|
84
|
+
- Add XML documentation to public procedures
|
|
85
|
+
- Use Error/FieldError for validation, not Message
|
|
86
|
+
- Wrap external calls in Try functions
|
|
87
|
+
- Log significant operations via Session.LogMessage
|
|
88
|
+
- Test edge cases, not just happy path
|
|
89
|
+
|
|
90
|
+
## Off-Limits
|
|
91
|
+
|
|
92
|
+
Do NOT:
|
|
93
|
+
- Modify FEATURES.json except to change "passes" field
|
|
94
|
+
- Remove or weaken existing tests
|
|
95
|
+
- Skip the orientation/verification steps
|
|
96
|
+
- Implement multiple features in one session
|
|
97
|
+
- Leave TODO comments without logging to ISSUES.md
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## PROGRESS.md Template
|
|
103
|
+
|
|
104
|
+
```markdown
|
|
105
|
+
# Integration Extension Progress
|
|
106
|
+
|
|
107
|
+
## Project Status: In Progress
|
|
108
|
+
Last Updated: 2024-01-16
|
|
109
|
+
|
|
110
|
+
## Completed Features
|
|
111
|
+
|
|
112
|
+
### Session 2024-01-15 (Evening)
|
|
113
|
+
**Feature**: Customer Lookup by External ID
|
|
114
|
+
**Commit**: abc1234
|
|
115
|
+
**Summary**:
|
|
116
|
+
- Added ExternalCustomerID field to Customer table extension
|
|
117
|
+
- Created CustomerIntegration codeunit with FindByExternalId function
|
|
118
|
+
- Added unit tests for lookup scenarios (found, not found, multiple matches)
|
|
119
|
+
- All tests passing
|
|
120
|
+
|
|
121
|
+
### Session 2024-01-16 (Morning)
|
|
122
|
+
**Feature**: Customer Create from External Data
|
|
123
|
+
**Commit**: def5678
|
|
124
|
+
**Summary**:
|
|
125
|
+
- Added CreateFromExternalData procedure
|
|
126
|
+
- Maps external fields to BC customer fields
|
|
127
|
+
- Sets default values for required fields (Customer Posting Group, etc.)
|
|
128
|
+
- Creates customer in pending state for review
|
|
129
|
+
- Tests cover creation and default value application
|
|
130
|
+
|
|
131
|
+
## Current Status
|
|
132
|
+
|
|
133
|
+
**Working On**: Customer Update Sync
|
|
134
|
+
**State**: Not started - ready for next session
|
|
135
|
+
|
|
136
|
+
**Next Up**:
|
|
137
|
+
1. Customer Update Sync (highest priority)
|
|
138
|
+
2. Error Logging infrastructure
|
|
139
|
+
3. Retry Mechanism
|
|
140
|
+
|
|
141
|
+
## Known Issues
|
|
142
|
+
|
|
143
|
+
| Issue | Severity | Notes |
|
|
144
|
+
|-------|----------|-------|
|
|
145
|
+
| Phone formatting inconsistent | Low | External system uses various formats |
|
|
146
|
+
| No duplicate detection | Medium | Should check for existing before create |
|
|
147
|
+
|
|
148
|
+
## Session Notes
|
|
149
|
+
|
|
150
|
+
- External API documentation: /docs/external-api.md
|
|
151
|
+
- Test credentials in launch.json (dev only)
|
|
152
|
+
- Mock responses in /test/mocks/ for offline testing
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## FEATURES.json Template
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"project": "Customer Integration Extension",
|
|
162
|
+
"lastUpdated": "2024-01-16",
|
|
163
|
+
"features": [
|
|
164
|
+
{
|
|
165
|
+
"id": 1,
|
|
166
|
+
"category": "core",
|
|
167
|
+
"description": "Customer lookup by external ID returns matching BC customer",
|
|
168
|
+
"acceptance": [
|
|
169
|
+
"FindByExternalId returns customer record when match exists",
|
|
170
|
+
"Returns empty record when no match",
|
|
171
|
+
"Handles multiple matches gracefully (logs warning, returns first)"
|
|
172
|
+
],
|
|
173
|
+
"passes": true,
|
|
174
|
+
"completedDate": "2024-01-15",
|
|
175
|
+
"commit": "abc1234"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"id": 2,
|
|
179
|
+
"category": "core",
|
|
180
|
+
"description": "New external customers create BC customer with defaults",
|
|
181
|
+
"acceptance": [
|
|
182
|
+
"CreateFromExternalData creates new customer record",
|
|
183
|
+
"Required fields populated with configured defaults",
|
|
184
|
+
"External ID stored for future lookups",
|
|
185
|
+
"Customer created in Pending status"
|
|
186
|
+
],
|
|
187
|
+
"passes": true,
|
|
188
|
+
"completedDate": "2024-01-16",
|
|
189
|
+
"commit": "def5678"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"id": 3,
|
|
193
|
+
"category": "core",
|
|
194
|
+
"description": "Customer updates sync specific fields from external system",
|
|
195
|
+
"acceptance": [
|
|
196
|
+
"Name, Address, Phone fields update from external data",
|
|
197
|
+
"Other fields remain unchanged",
|
|
198
|
+
"Update logged with before/after values",
|
|
199
|
+
"No update if no changes detected"
|
|
200
|
+
],
|
|
201
|
+
"passes": false
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"id": 4,
|
|
205
|
+
"category": "infrastructure",
|
|
206
|
+
"description": "Failed syncs log to Integration Log table with error details",
|
|
207
|
+
"acceptance": [
|
|
208
|
+
"Integration Log table captures: timestamp, operation, error, external ID",
|
|
209
|
+
"Failed operations do not stop batch processing",
|
|
210
|
+
"Log entries accessible via Integration Log page"
|
|
211
|
+
],
|
|
212
|
+
"passes": false
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"id": 5,
|
|
216
|
+
"category": "infrastructure",
|
|
217
|
+
"description": "Retry mechanism attempts failed syncs automatically",
|
|
218
|
+
"acceptance": [
|
|
219
|
+
"Job queue entry processes Integration Log failures",
|
|
220
|
+
"Retry attempts logged with count",
|
|
221
|
+
"Max retries configurable (default 3)",
|
|
222
|
+
"Successful retry updates log status"
|
|
223
|
+
],
|
|
224
|
+
"passes": false
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"id": 6,
|
|
228
|
+
"category": "ui",
|
|
229
|
+
"description": "Manual sync action available on Customer Card",
|
|
230
|
+
"acceptance": [
|
|
231
|
+
"Sync action visible when External ID populated",
|
|
232
|
+
"Action triggers immediate sync for single customer",
|
|
233
|
+
"Success/failure message displayed",
|
|
234
|
+
"Page refreshes to show updated data"
|
|
235
|
+
],
|
|
236
|
+
"passes": false
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Orientation Script Example
|
|
245
|
+
|
|
246
|
+
```markdown
|
|
247
|
+
## Session Start Script
|
|
248
|
+
|
|
249
|
+
When beginning a new session on this project, execute these steps in order:
|
|
250
|
+
|
|
251
|
+
### Step 1: Confirm Location
|
|
252
|
+
\`\`\`
|
|
253
|
+
pwd
|
|
254
|
+
# Expected: /workspaces/customer-integration
|
|
255
|
+
\`\`\`
|
|
256
|
+
|
|
257
|
+
### Step 2: Check Git Status
|
|
258
|
+
\`\`\`
|
|
259
|
+
git status
|
|
260
|
+
git log --oneline -5
|
|
261
|
+
\`\`\`
|
|
262
|
+
Look for: uncommitted changes, recent commit messages
|
|
263
|
+
|
|
264
|
+
### Step 3: Read Progress
|
|
265
|
+
\`\`\`
|
|
266
|
+
cat PROGRESS.md
|
|
267
|
+
\`\`\`
|
|
268
|
+
Understand: what's done, what's in progress, known issues
|
|
269
|
+
|
|
270
|
+
### Step 4: Check Features
|
|
271
|
+
\`\`\`
|
|
272
|
+
cat FEATURES.json | jq '.features[] | select(.passes == false)'
|
|
273
|
+
\`\`\`
|
|
274
|
+
Identify: next feature to implement
|
|
275
|
+
|
|
276
|
+
### Step 5: Verify Baseline
|
|
277
|
+
\`\`\`
|
|
278
|
+
# Compile extension
|
|
279
|
+
al: Download Symbols
|
|
280
|
+
al: Build
|
|
281
|
+
|
|
282
|
+
# Run tests
|
|
283
|
+
al: Run Tests
|
|
284
|
+
\`\`\`
|
|
285
|
+
Confirm: extension compiles, tests pass
|
|
286
|
+
|
|
287
|
+
### Step 6: Begin Work
|
|
288
|
+
Only after all checks pass, begin implementing the next feature.
|
|
289
|
+
If any check fails, fix the issue before new development.
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Commit Message Standards
|
|
295
|
+
|
|
296
|
+
```markdown
|
|
297
|
+
## Commit Message Format
|
|
298
|
+
|
|
299
|
+
Use conventional commit format for BC projects:
|
|
300
|
+
|
|
301
|
+
feat: [Object Type] [Feature Description]
|
|
302
|
+
fix: [Object Type] [Bug Description]
|
|
303
|
+
test: [Object Type] [Test Description]
|
|
304
|
+
docs: [Documentation Change]
|
|
305
|
+
refactor: [Object Type] [Refactor Description]
|
|
306
|
+
|
|
307
|
+
### Examples
|
|
308
|
+
|
|
309
|
+
feat: Codeunit CustomerIntegration - Add FindByExternalId function
|
|
310
|
+
feat: TableExt Customer - Add External Customer ID field
|
|
311
|
+
fix: Codeunit CustomerIntegration - Handle null response from API
|
|
312
|
+
test: Codeunit CustomerIntegrationTest - Add lookup edge cases
|
|
313
|
+
docs: README - Update setup instructions for external API
|
|
314
|
+
refactor: Codeunit CustomerIntegration - Extract field mapping logic
|
|
315
|
+
|
|
316
|
+
### Commit Body
|
|
317
|
+
|
|
318
|
+
For significant changes, include:
|
|
319
|
+
- What was implemented
|
|
320
|
+
- Why this approach was chosen
|
|
321
|
+
- Any known limitations
|
|
322
|
+
- Related features or issues
|
|
323
|
+
```
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Codeunit.Run() Error Handling Pattern"
|
|
3
|
+
domain: "eva-errors"
|
|
4
|
+
difficulty: "advanced"
|
|
5
|
+
bc_versions: "14+"
|
|
6
|
+
tags: ["codeunit-run", "error-handling", "transactions", "commit", "isolation"]
|
|
7
|
+
samples: "samples/codeunit-run-pattern.md"
|
|
8
|
+
related_topics:
|
|
9
|
+
- "try-function-usage.md"
|
|
10
|
+
- "testfield-error-handling.md"
|
|
11
|
+
---
|
|
12
|
+
# Codeunit.Run() Error Handling Pattern
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
The `if Codeunit.Run() then` pattern is a fundamental error handling mechanism in Business Central that enables transaction isolation and error recovery. Unlike try functions, this pattern allows write operations within its scope, making it essential for robust business process implementation.
|
|
17
|
+
|
|
18
|
+
**Core Principle**: Capturing the boolean result from Codeunit.Run() fundamentally changes its behavior—enabling isolated transactions with error suppression and recovery.
|
|
19
|
+
|
|
20
|
+
## How It Works
|
|
21
|
+
|
|
22
|
+
### Standard Codeunit.Run()
|
|
23
|
+
When you call `Codeunit.Run(CodeunitID)` without capturing the result:
|
|
24
|
+
- Executes in the current transaction context
|
|
25
|
+
- Errors propagate up and terminate execution
|
|
26
|
+
- No special transaction handling occurs
|
|
27
|
+
|
|
28
|
+
### Captured Result Pattern
|
|
29
|
+
When you call `if Codeunit.Run(CodeunitID) then`:
|
|
30
|
+
- A **new transaction** is started for the codeunit execution
|
|
31
|
+
- If the codeunit succeeds, the transaction is committed
|
|
32
|
+
- If the codeunit fails, the transaction is rolled back
|
|
33
|
+
- Errors are **suppressed**—they don't terminate execution
|
|
34
|
+
- The calling code continues regardless of success or failure
|
|
35
|
+
- The developer must capture errors using GetLastErrorText()
|
|
36
|
+
|
|
37
|
+
## Transaction Behavior
|
|
38
|
+
|
|
39
|
+
### Transaction Isolation
|
|
40
|
+
The captured Codeunit.Run() creates a transaction boundary:
|
|
41
|
+
- All database operations inside the codeunit are isolated
|
|
42
|
+
- Success commits all changes atomically
|
|
43
|
+
- Failure rolls back all changes completely
|
|
44
|
+
- The calling transaction is unaffected by the codeunit's outcome
|
|
45
|
+
|
|
46
|
+
### Critical Requirement: Commit Before Run
|
|
47
|
+
**Any open transaction MUST be committed before calling Codeunit.Run() with result capture.**
|
|
48
|
+
|
|
49
|
+
This is required because:
|
|
50
|
+
- The new transaction cannot begin while another is pending
|
|
51
|
+
- Uncommitted changes from the caller would be in an undefined state
|
|
52
|
+
- The runtime requires a clean transaction state
|
|
53
|
+
|
|
54
|
+
Failure to commit first will result in a runtime error.
|
|
55
|
+
|
|
56
|
+
## Implementation Guidelines
|
|
57
|
+
|
|
58
|
+
### Proper Placement
|
|
59
|
+
Use this pattern at logical boundaries in your processes:
|
|
60
|
+
- Between major process phases
|
|
61
|
+
- At the start of independent operations
|
|
62
|
+
- When calling potentially failing external integrations
|
|
63
|
+
- For batch processing individual records
|
|
64
|
+
|
|
65
|
+
### Avoid Mid-Process Usage
|
|
66
|
+
Do NOT use this pattern in the middle of a transaction sequence:
|
|
67
|
+
- Commit() has permanent effects—it cannot be undone
|
|
68
|
+
- Partial commits can leave data in inconsistent states
|
|
69
|
+
- Plan your process flow to have clean commit points
|
|
70
|
+
|
|
71
|
+
### Error Capture
|
|
72
|
+
Always capture and handle errors when using this pattern:
|
|
73
|
+
- Check the boolean result immediately
|
|
74
|
+
- Use GetLastErrorText() to get error details
|
|
75
|
+
- Log, notify, or take corrective action as appropriate
|
|
76
|
+
|
|
77
|
+
## Use Cases
|
|
78
|
+
|
|
79
|
+
### Batch Processing
|
|
80
|
+
Process multiple records where individual failures shouldn't stop the entire batch:
|
|
81
|
+
```
|
|
82
|
+
// Conceptual pattern:
|
|
83
|
+
foreach record in batch do begin
|
|
84
|
+
Commit(); // Clean slate for each record
|
|
85
|
+
if Codeunit.Run(ProcessorCodeunit, record) then
|
|
86
|
+
SuccessCount += 1
|
|
87
|
+
else begin
|
|
88
|
+
LogError(record, GetLastErrorText());
|
|
89
|
+
FailureCount += 1;
|
|
90
|
+
end;
|
|
91
|
+
end;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### External Integration Points
|
|
95
|
+
Isolate external system calls that include database updates:
|
|
96
|
+
- Prepare staging data
|
|
97
|
+
- Commit current transaction
|
|
98
|
+
- Run integration codeunit with capture
|
|
99
|
+
- Handle success or failure appropriately
|
|
100
|
+
|
|
101
|
+
### Optional Processing Steps
|
|
102
|
+
For process steps that should not block the main flow:
|
|
103
|
+
- Archive operations
|
|
104
|
+
- Notification sending
|
|
105
|
+
- Audit logging to external systems
|
|
106
|
+
|
|
107
|
+
## Comparison with Try Functions
|
|
108
|
+
|
|
109
|
+
| Aspect | Try Function | Codeunit.Run() Pattern |
|
|
110
|
+
|--------|--------------|------------------------|
|
|
111
|
+
| Write Operations | NOT allowed in call stack | Fully allowed |
|
|
112
|
+
| Transaction | Same transaction | New isolated transaction |
|
|
113
|
+
| Error Behavior | Caught, rolled back | Caught, isolated rollback |
|
|
114
|
+
| Commit Required | No | Yes, before the call |
|
|
115
|
+
| Use Case | External calls, validation | Business processes, batch |
|
|
116
|
+
|
|
117
|
+
## Best Practices
|
|
118
|
+
|
|
119
|
+
### Plan Transaction Boundaries
|
|
120
|
+
Design your process to have natural commit points before using this pattern. Don't force commits just to use Codeunit.Run().
|
|
121
|
+
|
|
122
|
+
### Create Dedicated Codeunits
|
|
123
|
+
Build codeunits specifically designed to be called with result capture:
|
|
124
|
+
- Self-contained logic
|
|
125
|
+
- Clear success/failure semantics
|
|
126
|
+
- Appropriate error messaging
|
|
127
|
+
|
|
128
|
+
### Document the Pattern
|
|
129
|
+
When using Codeunit.Run() with capture, add comments explaining:
|
|
130
|
+
- Why isolation is needed
|
|
131
|
+
- What the commit point means
|
|
132
|
+
- How failures are handled
|
|
133
|
+
|
|
134
|
+
### Error Handling is Mandatory
|
|
135
|
+
Never ignore the return value. The pattern's power comes from handling both success and failure cases appropriately.
|
|
136
|
+
|
|
137
|
+
## Common Mistakes
|
|
138
|
+
|
|
139
|
+
### Forgetting the Commit
|
|
140
|
+
Calling Codeunit.Run() with capture while a transaction is open causes runtime errors. Always commit first.
|
|
141
|
+
|
|
142
|
+
### Using Mid-Transaction
|
|
143
|
+
Forcing a Commit() in the middle of a logical transaction to use this pattern leads to data integrity issues.
|
|
144
|
+
|
|
145
|
+
### Ignoring Failures
|
|
146
|
+
Capturing the result but not acting on failures defeats the purpose and hides problems.
|
|
147
|
+
|
|
148
|
+
### Overusing the Pattern
|
|
149
|
+
Not every codeunit call needs isolation. Use this pattern when you specifically need independent transaction handling.
|
|
150
|
+
|
|
151
|
+
## Summary
|
|
152
|
+
|
|
153
|
+
The Codeunit.Run() pattern with result capture is essential for:
|
|
154
|
+
- Enabling error handling with database operations
|
|
155
|
+
- Isolating transactions for failure recovery
|
|
156
|
+
- Building robust batch and integration processes
|
|
157
|
+
|
|
158
|
+
Remember: **Commit() before, capture the result, handle errors explicitly.**
|
|
159
|
+
|