Creating and Debugging a Unified Service Desk Custom Hosted Control

Leave a comment

USD has the flexibility to create custom hosted controls. Here are the steps to do this.

  1. Download and install the Unified Service Desk templates for Visual Studio from the Microsoft website here: https://marketplace.visualstudio.com/items?itemName=DynamicsCRMPG.MicrosoftDynamicsCRMSDKTemplates

  2. Open Visual Studio. Create a new project, and under the CRM SDK Templates, select Unified Service Desk. Select UII WPF Hosted Control:

  3. This will create a project in Visual Studio like below:

  4. 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.

  5. Remove the missing references from the project by multi-selecting them and clicking delete.
  6. Browse out to the USD folder (located at C:\Program Files\Microsoft Dynamics CRM USD\USD) and select any of the missing references above.

  7. Expand the USDControl and open the CS file. Go to the DoAction:

  8. 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:

  9. Note in the DoAction we can check for which action is being called. We will expand on this later.
  10. 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.

  11. Copy the new TestHostedControl.dll to the USD client folder.
  12. We now need to configure this new custom hosted control in CRM. Open CRM and go to USD Hosted Controls:

  13. 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)

  14. Create new UII actions for the client. Go to UII Actions for the hosted control

  15. Run the USD client. Click on the Debugger, which is the toggle on the top right:

  16. Expand the selection and select Direct Action. Select the Hosted Control as the one we created – Test Hosted Control. Keep the Action as default:

  17. Press the play button to run the action for this control. We can see our Hello World dialog box appearing:

  18. We can also run this from Visual Studio and be able to debug the code. Let’s do this.
  19. 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:

  20. Build the project. Ensure USD is not started during the build or there will be build errors.
  21. Start the USD client from the directory located in the Build configuration.
  22. In Visual Studio, set a breakpoint in the code:

  23. In Visual Studio, from the Debug menu select Attach to Process and select the USD client:

  24. From the USD debugger, run the hosted control as a direct action:

  25. The debugger will then start:

  26. 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.

 

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *