USD has the flexibility to create custom hosted controls. Here are the steps to do this.
- Download and install the Unified Service Desk templates for Visual Studio from the Microsoft website here: https://marketplace.visualstudio.com/items?itemName=DynamicsCRMPG.MicrosoftDynamicsCRMSDKTemplates
- Open Visual Studio. Create a new project, and under the CRM SDK Templates, select Unified Service Desk. Select UII WPF Hosted Control:
- This will create a project in Visual Studio like below:
- Expand the references. Note there are several references that are contained in the project. In this case, there references are missing. We will need to add these back into the project from our USD installation.
- Remove the missing references from the project by multi-selecting them and clicking delete.
- Browse out to the USD folder (located at C:\Program Files\Microsoft Dynamics CRM USD\USD) and select any of the missing references above.
- Expand the USDControl and open the CS file. Go to the DoAction:
- The DoAction is the action we call from USD. Note there is sample code in the action. Let’s add some code to show a Hello World message box:
- Note in the DoAction we can check for which action is being called. We will expand on this later.
- Browse out to the Debug folder of the project. Note there is a DLL created for this project. There are also other files which reflect the USD client folder.
- Copy the new TestHostedControl.dll to the USD client folder.
- We now need to configure this new custom hosted control in CRM. Open CRM and go to USD Hosted Controls:
- Select New and enter a new hosted control as below:
Name = Test Hosted Control (anything works here)
Unified Service Desk Component Type = USD Hosted Control
Application Is Global (for the purpose of the demo)
Display Group = MainPanel (for the purpose of the demo)
Assembly URI = TestHostedControl (i.e. the namespace from the hosted control)
Assembly Type = TestHostedControl.USDControl (i.e. namespace.class)
- Create new UII actions for the client. Go to UII Actions for the hosted control
- Run the USD client. Click on the Debugger, which is the toggle on the top right:
- Expand the selection and select Direct Action. Select the Hosted Control as the one we created – Test Hosted Control. Keep the Action as default:
- Press the play button to run the action for this control. We can see our Hello World dialog box appearing:
- We can also run this from Visual Studio and be able to debug the code. Let’s do this.
- First, set up Visual Studio. Go to the Properties of the project, then Build, and go to the output path. Select the path to the USD client. When you build you may not be able to deploy to the USD folder due to permissions. To get around this you can make a copy of the original USD folder and use that below:
- Build the project. Ensure USD is not started during the build or there will be build errors.
- Start the USD client from the directory located in the Build configuration.
- In Visual Studio, set a breakpoint in the code:
- In Visual Studio, from the Debug menu select Attach to Process and select the USD client:
- From the USD debugger, run the hosted control as a direct action:
- The debugger will then start:
- You can now step through the code and view the variables:
Tip: If USD is throwing an error and you are not sure which custom hosted control is causing the problem, you can also use the debugger to run a direct action to close the hosted control. Select the hosted control and set the Action to Close. Run and this will close the control.