Writing your own automation using C#
C/AL is a solid programming language, and NAV is a great system, but it cannot always exactly do what we want it to. Luckily, we can write our own code in .NET and use it in NAV. This recipe will show you how to set up a Visual Studio project so that it can be seen from within the NAV client.
How to do it...
Create a new Class Library Project in Visual Studio.
Add the following code to the project:
using System.Runtime.InteropServices; namespace NAVAdd { [ClassInterface(ClassInterfaceType.AutoDual)] [ProgId("NAVAdd")] [ComVisible(true)] public class NAVAdd { public int Add(int a, int b) { return a + b; } } }
View the Properties for the project.
On the Application tab set the Assembly name to NAVAdd.
On the Build tab set the Register for COM interop property to true (checked).
Save and compile your objects.
Create a new codeunit in Object Designer.
Add the following global variable:
Name
DataType
SubType
NAVAdd
Automation
'NAVAdd'.NAVAdd
Add the following...