Writing a automation for Navision is pretty simple, when you first know how to do it
First of all, I assume that you already know about C#.
So here are the basic steps for creating an automation:
1. Create a new Class Library project.
- Chose File -> New -> Project and then chose Class Library and save it as myAutomation (or use you own name)
2. Before making any changes – setup the Properties
- Chose Project -> myAutomation Properties
- Select tab Application and then the button Assembly Information
- In the Assembly Information window, mark “Make assembly COM-Visible” and chose Ok
- Select tab Build
- Mark “Register for COM interop”
- Select tab Signing
- Mark “Sign the assembly” and create a key files (or chose an existing one)
Now everything is setup and you can close the property setup.
3. Add the namespace for InteropServices
- This is done by adding using System.Runtime.InteropServices
You should now have a code similar to the following:
using System;
using System.Text;
using System.Runtime.InteropServices;namespace myAutomation
{
……public class myAutomation
……{
……}
}
4. Declare the interface
First you have to decide if the class should be visible or not. In this case we want it to be visible, so that we can use it with the automation.
[ComVisible(true)]
Next you can choose to set the Guid and ProgId.
[Guid("41E646B3-F65C-4d8e-8539-499FA56C7076")]
[ProgId("myAutomation")]
Then decide the Class Interface Type. You can choose between None and Autodual.
[ClassInterface(ClassInterfaceType.AutoDual)]
For now we will be using Autodual, because None requires the use of Interface and class’es – where as Autodual only uses class.
You should now have a code similar to the following:
using System;
using System.Text;
using System.Runtime.InteropServices;namespace myAutomation
{
……[ComVisible(true)]
……[Guid("41E646B3-F65C-4d8e-8539-499FA56C7076")]
……[ClassInterface(ClassInterfaceType.AutoDual)]
……[ProgId("myAutomation")]
……public class myAutomation
……{
……}
}
Now you can add all the functions that you need.
Notice, you can hide functions and classes from the automation by using Private or [ComVisible(false)]
Here is a code example for an automation with visible and invisible methods.
using System;
using System.Text;
using System.Runtime.InteropServices;namespace myAutomation
{
……[ComVisible(true)]
……[Guid("41E646B3-F65C-4d8e-8539-499FA56C7076")]
……[ClassInterface(ClassInterfaceType.AutoDual)]
……[ProgId("myAutomation")]
……public class myAutomation
……{
………..public Int16 Add(Int16 X, Int16 Y)
………..{
…………….Int16 Result = (Int16)(X + Y);
…………….return Result;
………..}………..//Is hidden in the Automation because of Private
………..private Int16 PrivateAdd(Int16 X, Int16 Y)
………..{
…………….Int16 Result = (Int16)(X + Y);
…………….return Result;
………..}………..//Is hidden in the Automation because of ComVisible
………..[ComVisible(false)]
………..public Int16 InvisibleAdd(Int16 X, Int16 Y)
………..{
…………….Int16 Result = (Int16)(X + Y);
…………….return Result;
………..}
……}
}
Functions are in the automation presented as Methods, where as C# properties (public set; get;) are presented as properties.
Please note, that I am using Visual Studio C# 2008 (you can download the Express version from Microsoft here.)