Walkthrough: Create a UII Application Adapter.
The document is archived and information here might be outdated
Applies To: Dynamics CRM 2013, Dynamics CRM 2015, Dynamics CRM 2016, Dynamics CRM Online, Unified Service Desk 2.0
You can create an application adapter if you want to integrate an external application with Unified Service Desk. Microsoft Dynamics CRM provides a Microsoft Visual Studio template for creating an application adapter. The template provides basic code as comments to help you get started with creating the application adapter.
In this walkthrough, you'll build an external application QsExternalApp and host it in Unified Service Desk. You'll then create and configure an application adapter ExternalApplicationAdapter for the external application to interact with Unified Service Desk. The external application has four labels: one each for the customer's first name, last name, address and ID and four corresponding text boxes to display the values from Unified Service Desk.
< /div>-
Microsoft .NET Framework 4.5.2
-
Unified Service Desk client application; required for testing the hosted control.
-
Microsoft Visual Studio 2012, Visual Studio 2013, or Visual Studio 2015
-
NuGet Package Manager for Visual Studio 2012, Visual Studio 2013, or Visual Studio 2015
-
Microsoft Dynamics CRM SDK templates for Visual Studio that contains the UII hosted control project template. You can get it in one of the following ways:
-
Download the UII SDK package.
-
Double-click the package file to extract the contents.
-
Navigate to the <ExtractedFolder>\UII\SampleCode\UII\AIF\QsExternalApp folder, and open the Microsoft.Uii.QuickStarts.QsExternalApp.csproj file in Visual Studio.
-
Press F5 or choose Debug > Start Debugging to create a sample external application. The application (Microsoft.Uii.QuickStarts.QsExternalApp.exe) is created in the /bin/debug folder of the project.
In this step, you will create a hosted control of External Hosted Application type to display the Windows forms application.
-
Sign in to Microsoft Dynamics CRM.
-
On the navigation bar, click or tap Microsoft Dynamics CRM, and then select Settings.
-
Click or tap Settings > Unified Service Desk > Hosted Controls.
-
Click New.
-
On the New Hosted Control page, specify the following values:
Field
Value
Name
QsExternalApp
USD Component
CCA Hosted Application
Hosted Application
External Hosted Application
Application is Global
Checked
Display Group
MainPanel
Adapter
Use No Adapter
Application is Dynamic
No
External App URI
Microsoft.Uii.QuickStarts.QsExternalApp.exe
-
Click Save.
-
Copy the application from your Visual Studio project output folder (<ProjectFolder>\bin\debug) to the Unified Service Desk application directory. In this case, we will copy the Microsoft.Uii.QuickStarts.QsExternalApp.exefile to the C:\Program Files\Microsoft Dynamics CRM USD\USD directory.
-
Run the Unified Service Desk client to connect to your Microsoft Dynamics CRM server.
-
On successful sign in, you'll see the Sample External Application button on your desktop.
-
Choose Sample External Application to see your external application hosted within Unified Service Desk.
Note |
---|
At this point the fields are empty as you're only hosting the application in Unified Service Desk. To populate them with values from Unified Service Desk, you'll have to create an application adapter as described in the next step. |
-
Start Microsoft Visual Studio, and create a new project.
-
In the New Project dialog box:
-
From the list of installed templates, expand Visual C#, and select CRM SDK Templates > Unified Service Desk > UII Application Adapter
-
Specify the name and location of the project, and click OK to create a new project.
-
-
In Solution Explorer, expand the References section to ensure all the assembly references resolve correctly.
-
Open the AppAdapter.cs file and add the following lines of code to set the locations for each component on the page in the class definition.
// Set up your locations for each component on the page. // If you wish, you could use Spy++ to get the actual names as well. // First Name text box int intFirstNameCoordX = 47; int intFirstNameCoordY = 32; // Last Name text box int intLastNameCoordX = 223; int intLastNameCoordY = 32; // Address Text box int intAddressCoordX = 47; int intAddressCoordY = 81; // Customer ID text box int intIDCoordX = 47; int intIDCoordY = 126;
-
Add the following code to the definition of NotifyContextChange to notify the application that the context has changed. For more information, see NotifyContextChange
public override bool NotifyContextChange(Context context) { IntPtr ptr = MainWindowHandle; // Find the control (first name) by position IntPtr childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intFirstNameCoordX, intFirstNameCoordY)); // Fill data out Win32API.SetWindowTextAny(childHwnd, context["firstname"]); // Find the control (last name) by position childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intLastNameCoordX, intLastNameCoordY)); // Fill out the data Win32API.SetWindowTextAny(childHwnd, context["lastname"]); childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intAddressCoordX, intAddressCoordY)); Win32API.SetWindowTextAny(childHwnd, context["address1_line1"]); childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intIDCoordX, intIDCoordY)); Win32API.SetWindowTextAny(childHwnd, context["CustomerID"]); // Hands control back over to the base class to notify next app of context change. return base.NotifyContextChange(context); }
-
Add the following code to the override definition of DoAction to update the form fields with values from Unified Service Desk.
public override bool DoAction(Microsoft.Uii.Csr.Action action, RequestActionEventArgs args) { IntPtr ptr; IntPtr childHwnd; switch (args.Action) { case "UpdateFirstName": // Get locations of what you want to update and handles ptr = MainWindowHandle; childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intFirstNameCoordX, intFirstNameCoordY)); // Populate data into fields Win32API.SetWindowTextAny(childHwnd, args.Data); break; case "UpdateLastName": // Get locations of what you want to update and handles ptr = MainWindowHandle; childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intLastNameCoordX, intLastNameCoordY)); // Populate data into fields Win32API.SetWindowTextAny(childHwnd, args.Data); break; } return base.DoAction(action, args); }
-
Save your project, and build it (Build > Build Solution). After the project builds successfully, an assembly (ExternalApplicationAdapter.dll) is generated in the \bin\debug folder of your project folder. You'll need this assembly later for testing and using your application adapter.
-
Sign in to Microsoft Dynamics CRM.
-
On the nav bar, choose Microsoft Dynamics CRM, and then select Settings.
-
Choose Settings > Unified Service Desk > Hosted Controls.
-
From the list of hosted controls, select the QsExternalApp hosted control.
-
In the Adapter Configuration section, specify the following values:
Field
Value
Adapter
Use Adapter
URI
ExternalApplicationAdapter
Type
ExternalApplicationAdapter.AppAdapter
Note URI is the name of your assembly and the Type is the name of your assembly (dll) followed by a dot (.) and then the class name in your Visual Studio project. In this example, the name of the assembly is ExternalApplicationAdapter and name of the class is AppAdapter, which is the default class name when you create an application adapter.
-
Click Save to save the changes.
-
Copy the assembly that contains your application adapter definition from your Visual Studio project output folder (<ProjectFolder>\bin\debug) to the Unified Service Desk application directory. In this case, we will copy the ExternalApplicationAdapter.dll file to the c:\Program Files\Microsoft Dynamics CRM USD\USD directory.
-
Run Unified Service Desk client to connect to your Microsoft Dynamics CRM server.
-
On successful sign in, you'll see the sample external application on your desktop.
-
Choose Search and then choose Contacts and select a contact. In this case, we'll select Patrick Sands.
-
Click Sample External Application and you'll see the customer's first name, last name, address, and ID populated.
Unified Service Desk 2.0
© 2016 Microsoft. All rights reserved. Copyright
Source: www.bing.com
Images credited t o www.bing.com and www.citygare.com