Built-in functions in Microsoft Dynamics 365 Business Central are pre-defined code units (methods) that perform common tasks like data manipulation, string handling, and system interactions, available directly in AL language and C/AL. They save developers from writing repetitive logic, enabling faster and more reliable customizations.
What Are Built-in Functions in Business Central?
Business Central uses AL (Application Language) for extensions and customizations. Built-in functions are part of the base application and the platform runtime, accessible without additional libraries. They operate on data types (e.g., integers, text, records), system objects (e.g., sessions, permissions), and business logic (e.g., posting, VAT). Examples include StrPos (find substring), CalcFields (calculate flowfields), and Insert (add a record). These functions are documented in Microsoft’s AL API reference and are versioned—some are deprecated over time.
Background: From C/AL to AL
Historically, Business Central (formerly NAV) used C/AL, a Pascal-like language. Built-in functions were part of the C/AL runtime. With the shift to AL (introduced in 2017 for extensions), Microsoft reorganized functions into namespaces like System, Data, and Business. Many C/AL functions were renamed or moved. For instance, CALCFIELDS became CalcFields in AL. This migration matters because existing code must be converted, and new development should target AL functions. The platform also added new functions like IsNullGuid and GetUrl for modern scenarios.
How Built-in Functions Work: Key Categories
Built-in functions fall into several logical groups:
- Data manipulation:
Insert,Modify,Delete,Geton records;CalcFields,CalcSumsfor flowfields;SetRange,SetFilterfor filtering. - String handling:
CopyStr,DelStr,StrPos,StrLen,LowerCase,UpperCase,PadStr. - Math and conversion:
Round,Abs,Power,Format,Evaluate(string to value). - Date and time:
Today,Now,Date2DMY,CalcDate(add days),WorkDate. - System and sessions:
GetUserID,GetUserName,IsNullGuid,Sleep,Error(raise message). - Business logic:
CheckPostingDate,CalcVATAmount,TestField(validate field).
Each function has a defined signature. For example, StrPos takes two text arguments and returns an integer position. Calling a function is straightforward: position := StrPos('hello world', 'world');.
How to Choose the Right Built-in Function
Selecting the correct function depends on your goal. For performance, prefer set-based operations like CalcFields over looping and calling Get repeatedly. For validation, use TestField instead of manually checking IsNull and error messages. For date arithmetic, CalcDate handles business days if configured. When unsure, consult the AL API reference in Visual Studio Code (with the AL extension). Also, consider whether a function is marked as “obsolete”—Microsoft deprecates functions with a version notice. For example, CalcFields is preferred over older CALCFIELDS in C/AL. Use the built-in IntelliSense in VS Code to see available functions and their parameters.
Common Problems and Misconceptions
One frequent issue is assuming built-in functions are always available in all scopes. Some functions are only for internal use or require specific permissions. For instance, GetUrl might fail if the server is not configured. Another misconception: CalcFields does not update the database—it only calculates in memory. Also, string functions are case-sensitive by default; use LowerCase before comparing if needed. A common error is using StrPos when the substring is not found—it returns 0, not an exception. Always check the return value. Finally, do not confuse built-in functions with system tables or codeunits—they are different. For example, Codeunit.Run is a method, not a built-in function.
Comparing Built-in Functions with Custom Code
Built-in functions are optimized and tested by Microsoft, so they are faster and safer than writing your own loops or string parsers. However, they may not cover niche business logic. Custom functions (procedures in AL) give flexibility but require more maintenance and testing. For example, a custom function to calculate a discount might be needed because no built-in covers your exact rule. Use built-ins as building blocks—combine them in custom procedures. Also, note that some built-in functions have limitations: CalcFields works only on flowfields, not on regular fields. For complex aggregation, you might need to write a query or use a temporary table.
Costs and Licensing Considerations
Built-in functions themselves are free—they are part of the Business Central license. However, development time is not free. Using built-ins reduces coding time, which lowers implementation costs. But be aware of performance costs: calling functions like CalcFields on large datasets can slow down if not used with filters. Also, some functions like Sleep should be avoided in production because they block the session. There are no extra licensing fees for using specific functions. But if you need advanced features not covered by built-ins, you might purchase an AppSource extension, which has its own cost. Always test performance in a sandbox.
Safety and Best Practices
When using built-in functions, follow these safety rules:
- Always validate input before passing to functions that expect specific formats (e.g., dates).
- Use
Errorfunction to throw exceptions, but avoid catching them unless necessary. - Be careful with functions that modify data—like
InsertorModify—they are not undoable. Always test in a sandbox first. - For security, do not use
Evaluateon untrusted user input; it can cause type confusion. - Check permissions: some functions like
GetUserIDwork only in certain contexts. - Use
IsNullGuidbefore comparing GUIDs to avoid errors.
For example, before calling CalcDate, ensure the date is valid. Also, remember that Round follows banker’s rounding by default—use the optional parameter for standard rounding.
Alternatives to Built-in Functions
If a built-in function does not exist or is insufficient, you have alternatives:
- Use AL system library codeunits like
SystemorDate—they contain additional methods. - Write your own procedure in AL, using built-ins as building blocks.
- Use .NET interoperability (via
DotNettype) for advanced tasks, but this is less supported and can break in cloud. - For complex business logic, consider using a Custom API or external service.
- Use Power Automate or Power Apps for simpler integrations, but these are not AL functions.
For example, to get the number of days between two dates, you can use Date2DMY or simply subtract dates—the result is an integer. No built-in function is needed.
Frequently Asked Questions
Q: Where can I find a list of all built-in functions?
Microsoft’s AL API Reference (docs.microsoft.com/dynamics365/business-central/dev-itpro/developer/reference) lists all built-in functions by namespace and data type. In VS Code, the AL extension provides IntelliSense as you type.
Q: Are built-in functions the same in C/AL and AL?
No. C/AL functions are legacy and often have different names (e.g., CALCFIELDS vs CalcFields). AL is the current standard. Microsoft provides a conversion tool for upgrading.
Q: Can I use built-in functions in a report or a query?
Yes, but with limitations. In reports, you can use functions in triggers like OnAfterGetRecord. In queries, you cannot call functions directly—you must use a codeunit or a view. For complex calculations, use a temporary table.
Q: How do I handle errors from built-in functions?
Most functions throw an error if invalid input is given. Use try-catch in AL (with try and catch keywords) to handle exceptions. For example, Evaluate can fail; wrap it in a try block.
Q: Do built-in functions work on Business Central online (cloud)?
Yes, but some functions that require local file access or .NET are not available in the cloud. For example, File functions are limited. Always check the documentation for “on-premises only” notes.
Q: Can I create my own built-in function?
You cannot extend the base set, but you can create your own procedures in codeunits and call them like built-ins. These are not “built-in” but are reusable across your extensions.
Related
- Control Shortcuts for Windows: Full List & How to Use Them
- Kindergarten Progress Report Template: What to Include
- What Speed Do Speed Cameras Catch You At?
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel Median IF: Formula & ExamplesTo calculate a median in Excel based on a condition, use the MEDIAN function together with IF in…
- Excel Formula to Pull Out Text Between Two CharactersTo pull text out from between two characters in Excel, use MID with FIND. If A2 contains Order…
- Sort Excel by Number: Steps, Options, and Common FixesTo sort numbers in Excel, select a cell in the number column, then choose Data > Sort Smallest…
- Cash Flow Formula in Excel for Net Present Value (NPV)For regular, evenly spaced cash flows, Excel’s net present value formula is =NPV(rate, future_cash_flows)+initial_cash_flow. Put the initial investment…
- Excel 2013 Array Formulas: How to Enter and Use ThemIn Excel 2013, an array formula performs calculations on one or more sets of values and may return…
- Filter Excel Using Multiple Criteria: Steps and TipsTo filter Excel using multiple criteria, select a cell in your data and choose Data > Filter, then…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.