понедельник, 19 сентября 2016 г.

The creation of the fields which are displayed in blue on the page

Plan

  • Creating an Add-in with Visual Studio.
  • Copying the Add-in Assembly to the Microsoft Dynamics Windows Client.
  • Registering the Add-in in Microsoft Dynamics NAV.
  • Setting Up the Add-in on a Page.


Creating an Add-in with Visual Studio

To create the add-in
1.      In Visual Studio, on the File menu, choose New, and then choose Project.
2.      Under Installed Templates, choose Visual C#, and then choose Class Library.
3.      In the Solution Name text box, enter the name of your solution. For example, you can enter MyCompany.MyProduct.RtcAddins and then choose the OK button.
Yow will add references to the following assemblies:
    1. Microsoft.Dynamics.Framework.UI.Extensibility.dll 
    2. System.Windows.Forms 
    3. System.Drawing 
4.      In Solution Explorer, right-click your project, and then choose Add Reference.
5.      In the Add Reference window, on the Browse tab, navigate to the location of the Microsoft.Dynamics.Framework.UI.Extensibility.dll assembly on your computer and then choose the OK button. By default, the path of the assembly is C:\Program Files (x86)\Microsoft Dynamics NAV\90\RoleTailored Client.
6.      In Solution Explorer, choose Reference, and on the shortcut menu, choose Add Reference.
7.      In the Add Reference window, choose the .NET tab, then under Component Name, choose System.Windows.Forms, and then choose theOK button.
The namespace contains classes for creating user interfaces for Windows-based applications.
8.      Repeat the previous step and add a reference to the System.Drawing namespace. This namespace provides access to basic graphics functionality.
9.      Open the Class1.cs file and add the following using directives.
10. In the ClassLibrary1 namespace, add the following code to declare a new class named MyFieldPopupAddin for the add-in.
11. In the MyFieldPopupAddin class, add the following code to implement the abstractMicrosoft.Dynamics.Framework.UI.Extensibility.WinForms.WinFormsControlAddInBase.CreateControl method and define the add-in functionality.

An assembly must be signed that can be used in the Microsoft Dynamics NAV Windows client. You will now sign the assembly.

To sign the assembly

1.      In Visual Studio, on the Project menu, choose MyCompany.MyProduct.RtcAddins properties.
2.      In the Properties window, choose Signing, and then select the Sign the assembly check box.
3.      In the Choose a strong name key file drop-down list, select New.
4.      In the Key file name text box, enter RtcAddins and clear the Protect my key file with a password check box.
In this walkthrough, you will not protect the key file with a password. However, you can choose whether to use a password. For more information, see Strong-Name Signing for Managed Applications.
5.      Choose the OK button.
6.      In Solution Explorer, choose the Class1.cs file to open it. Notice the RtcAddins.snk file that is added in Solution Explorer.
7.      On the Build menu, choose Build <Your Solution> to build the project. Verify that the build succeeds. In this example, your solution is MyCompany.MyProduct.RtcAddins.

Copying the Add-in Assembly to the Microsoft Dynamics Windows Client


After you build the add-in, you copy the output assembly file to the computer that is running the Microsoft Dynamics NAV Windows client.

To copy the add-in assembly to the Microsoft Dynamics NAV Windows client

1.      On the development computer, locate and copy the add-in assembly file (.dll file) in the add-in project's output folder.
By default, this folder is C:\ Documents\Visual Studio\Projects\[Your Addin Project]\[Your Class Library]\bin\Debug. In this case, the location of the assembly is C:\ \Documents\Visual Studio 2012\Projects\MyCompany.MyProduct.RtcAddins\ MyCompany.MyProduct.RtcAddins\bin\Debug.
2.      On the computer that is running the Microsoft Dynamics NAV Windows client, paste the assembly in the Microsoft Dynamics NAV Windows client\Add-ins folder in the Microsoft Dynamics NAV 2016 installation folder.
By default, the path of this folder is C:\Program Files (x86)\Microsoft Dynamics NAV\90\RoleTailored Client\Add-ins.

Registering the Add-in in Microsoft Dynamics NAV


To register an add-in, you include it on the Control Add-ins page in Microsoft Dynamics NAV. To include an add-in on the page, you must provide the following information:
  •       Control Add-in name.
The control add-in name is determined by the Microsoft.Dynamics.Framework.UI.Extensibility.ControlAddInExportAttribute attribute value of add-in class definition that you specified when you created the control add-in. The name in this walkthrough isMyCompany.MyProduct.FieldPopupAddin, as shown in the following code snippet from interface definition.

  •      Public key token.
To determine the public key token for the add-in
1.      On the Windows taskbar, choose Start, choose All Programs, choose Microsoft Visual Studio 2012, choose Visual Studio Tools, and then choose Visual Studio Command Prompt (2012) to open the command prompt.
2.      At a command prompt, change to the directory that contains the assembly that you copied.
For example, C:\Program Files (x86)\Microsoft Dynamics NAV\90\RoleTailored Client\Add-ins.
3.      Type the following command.
4.      sn -T <assembly>
Replace <assembly> with the assembly name, such as ClassLibrary1.dll.
5.      Press Enter and note the public token key that is displayed.

      To include the add-in on the Control Add-ins page

1.      In the Microsoft Dynamics NAV Windows client, in the Search box, enter Control Add-ins, and then choose the relevant link.
2.      On a new row, in the Control Add-ins page, enter the Control Add-in name, and the Public Key Token.
In this walkthrough, the add-in name is MyCompany.MyProduct.FieldPopupAddin.
3.      Choose the OK button to close the Control Add-ins page.

Setting Up the Add-in on a Page


In this section, you will modify the Customer Card page to use the new add-in on the name field. This involves the following tasks:
  •     Setting the ControlAddin Property of the field to the add-in.
  •     Setting the OnControlAddin Trigger.
In the C/AL Editor, you set the trigger that is called when a user selects the field to open a pop-up window. When a field is double-clicked, the add-in raises the Microsoft.Dynamics.Framework.UI.Extensibility.IEventControlAddInDefinition.ControlAddIn event, which in turn calls the trigger.

To set the ControlAddIn property on the field

1.      In Microsoft Dynamics NAV, in Object Designer, choose Page.
2.      Select page 21, Customer Card, and then choose Design.
3.      In the Page Designer, in the Name column, select the Name field, and then on the View menu, choose Properties.
4.      In the <Name> Properties window, in the Property column, locate ControlAddIn.
5.      In the Value column, choose the up arrow, and then select MyCompany.MyProduct.FieldPopupAddin from the Client Add-in window. Choose the OK button to close the Client Add-Ins window. The public key token is inserted into the Value field.
6.      Close the Properties window.
7.  On the File menu, choose Save, select the Compiled check box, and then choose the OK button.
8.      Close the C/AL window.

To test the add-in

1.      In Object Designer, choose Page. In the Name column, select the Customer Card page, and then choose Run. The customer card view is displayed. Notice the color of the Name field.