Discover how to improve your processes in Business Central using AL to extract numbers from text.
Learn to create a Codeunit and a page extension that filter numbers in text strings, thus optimizing data cleaning and task automation in your projects.

This blog is aimed at developers and system administrators working with Business Central who seek efficient ways to manipulate and process textual data.
By implementing this technique, you can improve data accuracy, facilitate cleaning and normalization of information, and automate repetitive tasks, ultimately increasing productivity and operational efficiency in your projects.
Why is extracting numbers from text useful in Business Central?
In Business Central, data manipulation and cleaning are essential tasks for maintaining the accuracy and efficiency of business processes.

Extracting numbers from text can be crucial in situations such as:
- Data cleaning and normalization: Ensures data is in the correct format, eliminating unwanted characters.
- Specific calculations: Facilitates the extraction of numeric values for mathematical operations.
- Task automation: Improves automation through more precise input data preparation.
Implementation of the Solution
Imagine you have a requirement where you need to manipulate a text and extract only the numbers it contains. This can be useful in a variety of situations, from cleaning data to performing specific calculations.
To address this challenge, we will use a simple but ingenious code through the following steps:
1st. We create a codeunit called "ProcesoSoloNumeros" with a procedure (function) called "DejarSoloNumeros".
This procedure takes text as input and returns only the numbers found in that text.

The code itself is quite simple. We use a "for" loop to get each character from the input text. Then, we check if each character is a number and, if so, add it to the output text. This approach allows us to effectively filter numbers from the rest of the text.
In the practical application of this code, imagine we're working on a customer extension page in Business Central. You want to display only the numbers from a text you receive as input.
2nd. We create a page extension that uses our code to extract and display the numbers from a sample text.
When running the page, we'll see that the original text, "XR12AB3D45", transforms into "12345", showing only the numbers present in the text.
This example is just the tip of the iceberg when it comes to the possibilities offered by programming in Business Central. From manipulating data to automating processes, the potential is unlimited. You can experiment with this code and discover how you can apply it to your own projects.
Remember, in the world of programming, creativity and problem-solving are your best allies…
Now, to verify that all this has worked correctly, we create a new page that executes this code in the OpenPage and shows us the result message.

Test and Validation
To validate our code, we will create a new page in Business Central that executes the "DejarSoloNumeros" procedure and displays the result.

When running this page, we should see a message displaying «12345», confirming that our procedure has correctly extracted the numbers from the original text.
Benefits of number extraction in Business Central
Implementing number extraction in Business Central brings multiple benefits:
- Improved data accuracy: Eliminates unwanted characters and ensures numerical data is correctly formatted.
- Facilitates automation: Prepares data for automated processes, reducing errors and increasing efficiency.
- Optimizes data cleaning and normalization: Simplifies data processing, ensuring it's ready for use in calculations and analysis.
With this technique, developers and system administrators can significantly improve the manipulation and processing of textual data in Business Central, thus optimizing their operations and business processes.
Read also: How to change item dimensions in Business Central
¿Are you looking for expert assistance with Microsoft Dynamics 365 Business Central?
At ABD, we are experts in Microsoft Dynamics 365 Business Central, with over 30 years of experience in technology solutions.

We offer implementation and development of customized solutions that optimize business processes. Our Microsoft-certified team is ready to help you transform your business with continuous technical support.
Contact us to discover how we can tailor our solutions to your company’s specific needs.
I hope you find it helpful.
Dynamics Programming –