Copy-paste of code is an integrated part of any developer’s daily work routine, but what’s the right way for copying Business Central code? Here’s my opinion:

We all copy code — it’s a natural part of development. When trying something new, we find examples that look like what we need and adapt them. When building something similar to what we’ve done before, we track it down and reuse it. This video isn’t about the bugs you might introduce by copying code (let Erik know in the comments if you want that video). Instead, it’s about where you copy from — and why there’s really only one best source.
The One Place You Should Copy From
The secret? Copy from Microsoft.
Whenever you want to build something in Business Central, chances are it’s going to be similar — to some degree — to something Microsoft has already implemented in the base app or one of their other apps. Their code is production-quality, battle-tested, and represents the proper way to implement most patterns in Business Central.
You’re not copying code that some random person created as a quick example. You’re copying production code that works in Microsoft’s actual product.
Example 1: Creating a Journal Page
Let’s say a customer asks you to create a journal — something like the Item Journal. You notice the Item Journal has a unique layout: there’s a batch name selector at the top, the action bar appears in the middle of the screen, journal lines sit below that, and there’s additional content at the bottom. This is because it uses a special page type.
Step 1: Inspect the Page
The first step is to figure out what page you’re looking at. Open the Page Inspector in Business Central, and you’ll see that the Item Journal is Page 14.
Step 2: Open the Base App Source
In Visual Studio Code, open the base app. If you have the AL Dev Tools extension installed, you can select an app file (like the base app), and it will load all the objects contained within it. Search for Page 14, double-click it, and you’ll get the full source code.
Note: This only works if the code is available in symbols. The base app supports this just fine.
Step 3: Study the Structure
Looking at the Item Journal source, the first thing you’ll notice is:
PageType = Worksheet;
This isn’t a List or a Card — it’s a Worksheet. The page type controls the overall layout and formatting of the page. Examining the layout section reveals the key structure:
- A layout section containing a content area and a FactBox area
- Inside content: a single field (the batch name selector), followed by a repeater (the journal lines), followed by a group (summary information at the bottom)
The batch name field at the top uses a global variable (like CurrentJournalBatchName). If you want to implement the journal batch selector, you can see that it uses an OnLookup trigger to handle the lookup and an OnValidate trigger to change the filter and show the correct records. All of this logic is right there for you to study and adapt.
So instead of finding some random page on the internet where somebody built something vaguely similar — if you want to create something like the Item Journal, go copy the Item Journal.
Example 2: Implementing the Camera Interface
Another great example: let’s say you want to use the camera functionality in Business Central. The Customer Card has a “Take Picture” action for the customer photo. Using Page Inspector, you can see this is Page 785 (Customer Picture).
Finding the Camera Code
Opening Page 785 in the base app source and looking at the actions, you’ll find an action called Take Picture. The key patterns to copy are:
- The action’s visibility is controlled by a
CameraAvailablevariable — so the button only shows up when there’s actually a camera available - On the
OnOpenPagetrigger, the code calls into the Camera codeunit to check if a camera is available and sets that variable - The action itself calls
Camera.GetPictureto capture an image into a stream, then imports that stream into a media field on the record
This is highly copyable code. Implementing the camera is not a big deal when you can just copy this pattern and adapt it to your own table and page. The camera availability check, the picture capture, the stream handling — it’s all right there.
Why This Approach Works
The advantage of copying from Microsoft’s apps is significant:
- It’s production code. This isn’t a simplified demo or a quick example — it’s code that runs in Microsoft’s shipping product.
- It follows best practices. This is the proper way to implement most patterns in Business Central.
- It’s comprehensive. You get to see all the edge cases and supporting logic that a blog post or tutorial might skip.
- The results are better. Your implementation will be more consistent with the rest of Business Central.
The General Pattern
- Identify what you want to build
- Find the closest equivalent in Business Central’s existing functionality
- Use the Page Inspector to identify the page or object number
- Open the base app (or relevant app) source in VS Code using the AL Dev Tools extension
- Search for that object, study its structure, and copy the patterns you need
Conclusion
Want to create a journal? Copy the journal. Want to implement a camera feature? Copy the camera code. Want to build something that resembles an existing feature? Find that feature in the running apps and copy from there. The result will be far better than copying code from some random internet page. Microsoft’s base app is your best reference — use it.
There are a couple of exceptions to this rule (Erik hints at a possible future video on that topic), but in most cases, the base app is the gold standard for code you should be copying.