Tip of the Week #116 – The Power of DotNet in Dynamics NAV

Tip of the Week #116 – The Power of DotNet in Dynamics NAV

Developer Peter Tijsma brings us this week’s informative tip.

As a developer, you often come across ‘missing’ functionality in C/AL (The Development Language in Dynamics NAV) which is so obvious in the .Net language.

This week, I would like to show you a small benefit of DotNet which I use quite often:

Question: “How would you replace a piece of text inside a given sentence with Dynamics NAV?”

The answer from the old days would probably look something like this:

The resulting message would then show:

However, the 6 lines of C/AL code can simply be replaced by only 2 lines of code using the power of DotNet:

But what if you want to make the replacement Case-Insensitive, then the original C/AL code would become even more complicated:

Since the ‘Replace’ method of the ‘String’ Class does not have this possibility, there’s always another smart way of doing this using DotNet.

The answer to this is to use the ‘RegEx’ (Regular Expressions) Class with the following 1-liner:

This is just one of the many ways you can use DotNet inside Dynamic NAV.


Reference links to MSDN:

String.Replace: https://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx

RegEx.Replace: https://msdn.microsoft.com/en-us/library/taz3ak2f(v=vs.110).aspx

Have Fun!

Thank you Peter!