Microsoft Dynamics 365 Blog

There is a number of posts and articles that show what you can really achieve with Client Extensibility in NAV 2009 SP1. This post goes the exact opposite way, to show the simplest possible example of a Client Extensibility add-in which includes callbacks between RTC and the Add-In, both ways:


In Visual Studio, add references to Microsoft.Dynamics.Framework.UI.Extensibility, System.Windows.Forms and (just to add colours) System.Drawing.


To add the first one, browse for “Microsoft.Dynamics.Framework.UI.Extensibility.dll” which is in the RTC folder. The other references used here are both under “.NET”:


 


References


Then you need to sign the project. In Visual Studio 2008, under Project Properties, go to the Signing tab, tick “Sign the Assembly”, and create a new key (type anything as the key name).


And here is the code needed to create a simple add-in, in this example just a button:


 


 


using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


using Microsoft.Dynamics.Framework.UI.Extensibility;


using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;


using System.Windows.Forms;


using System.Drawing;


namespace zDemo


{


[ControlAddInExport(“zDemo”)] // Interface – this is the name that is registered in NAV


public class zDemoButton : StringControlAddInBase


{


// Initialise what you want to create, then return it to RTC


protected override Control CreateControl()


{


Button B = new Button();


B.BackColor = Color.LemonChiffon; // Just so it stands out in the page


B.Click += this.OnButtonClick; // This is needed for calling NAV trigger (function below)


return (B);


}


// No other code is needed to create the add-in,


// But if you also want to exchange data between the add-in and NAV, then continue


// Receive data from NAV


public override string Value


{


get


{


return base.Value;


}


set


{


if (Convert.ToString(value) != “”)


{


((Button)this.Control).Text = Convert.ToString(value);


}


}


}


// Run NAV trigger OnControlAddIn


private void OnButtonClick(object sender, System.EventArgs e)


{


this.RaiseControlAddInEvent(1, “Button”);


}


}


}


 


Finally build the project. Copy your new dll and pdb file into the add-ins sub folder of RTC. Use the syntax sn -T [MyNewDll] from a Visual Studio command prompt to get the Public key token from your new dll. Register it in table 2000000069 “Client Add-in” with its name and Public key token, then add it to a page. To send data to the add-in, you also need to specify the “SourceExpr”-property. This can be either a variable or a field. In this case, it will just display the source expression on the button.


For the purpose of keeping this post minimal, I won’t go into any further details here, but I will mention one thing: I found that this line:


if (Convert.ToString(value) != “”)


is important. It seems that some times, the page calls the add-in multiple times, and some times with a blank value. So if not testing that RTC has actually sent some data to the add-in, you may be overwriting with blank data, and you may spend time to work out why this part is not working.


 


 


Lars Lohndorf-Larsen


Microsoft Dynamics UK


Microsoft Customer Service and Support (CSS) EMEA

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!