How to Create a Dynamics CRM Solution – Emailing Individual Team Members in CRM

This is going to be a rather complex technical article covering how to create the custom workflow step required to email all individual users in a team. This is useful for support desks or situations where you can’t or don’t want to directly email the team.

I’ll try my best to simplify this topic enough so that an individual with little to no prior experience should be able to follow it, however, if you just need to implement the functionality quickly and don’t mind paying for it I believe there are some companies or solutions online which may do this.

If you’re just wanting the code itself then check out my GitHub project – https://github.com/ShaunWilkinson/CreateActivityPartyFromString

Requirements

Before we get started you will need at least the following –

Create the Custom Workflow Step

In this stage, I’m working on the assumption that you have Visual Studio installed, the latest CRM SDK Tools and administrator permissions. If you don’t I’m sure there are plenty of guides online that can assist but if not comment below and I’ll make some.

  1. Open Visual Studio, expand the File tab > New > Project.
    emailTeamMembers1
  2. In the window that opens expand Visual C# > Workflow and select ‘Activity Library’.
  3. Give the project a name in my case I’ll just call it “EmailTeam” and change the Framework to be ‘.NET Framework 4.5.2’.
  4. Click OK and the project should be created.
  5. On the right-hand side, you should see the Solution Explorer window. Right-click ‘Activity1.xaml’ and select ‘Delete’. We won’t be needing this.
  6. Now right-click the ‘References’ entry in the Solution Explorer and select ‘Add Reference…’.
    emailTeamMembers2
  7. A window will pop up, click ‘Browse…’ at the bottom-right.
  8. If you downloaded the CRM SDK Tools using the link I provided then you can navigate to ‘C:\Dynamics Dev Tools\Tools\PackageDeployment’ and select the files listed below, otherwise, locate the files below wherever you’ve downloaded the SDK.
    • Microsoft.Crm.Sdk.Proxy.dll
    • Microsoft.Xrm.Sdk.dll
    • microsoft.xrm.sdk.workflow.dll
  9. Click Ok then OK in the window to import the dll files.
  10. Once that’s done, right-click the name of your project just right of the small green c# logo in the Solution Explorer, then click Add then Class.
  11. Give it a descriptive name such as ‘CreateActivityPartyFromTeam’ then click Add.
  12. You’ll now have a Class file which we can add some code into. I’ll cover that in the section below.

The Code

Now we’re going to populate the class file and then build the project, due to formatting restrictions in WordPress I’m just going to link you to the code on GitHub, be sure to follow the instructions below rather than just copying and pasting it all otherwise you will run into issues.

  1. Open the link below containing all of my code –
  2. Copy the entire file and paste it into your class in Visual Studio.
  3. Initially, you’re going to see a lot of errors and it’s easy to think you’ve done something wrong but it’s just because we haven’t yet added any References which are self-contained modules of code which we use (in this case it’s the CRM SDK).
  4. Right-Click ‘References’ in the Solution Explorer on the right and select ‘Add references’.
  5. In the window that appears go to the Browse page if you’re not on it already then click ‘Browse’ at the bottom right.
  6. Navigate to the CRM SDK that you downloaded and go into the ‘CoreTools’ folder.
  7. Select the following files then click Add –
    • Microsoft.Crm.Sdk.Proxy.dll
    • Microsoft.Crm.Sdk.dll
  8. Click OK in the Reference Manager window. Most of the errors will disappear but we’re still missing a reference.
  9. Right-Click References again and then select ‘Manage Nuget Packages’.
  10. Do a search for ‘Microsoft.Crmsdk.workflow’ and install the latest stable version that is supported by your CRM. In my case, this is 8.2.0.2 at the time of writing.
  11. Click OK to any warnings.
  12. All going well you should now have no errors at all displaying in Visual Studio.

Signing the Project

In order for the code to execute in CRM we need to sign it, which we do by creating a certificate. Luckily this is very easy to do in Visual Studio.

  1. Right-Click the name of the project in the Solution Explorer on the right-hand side and select Properties.
    emailTeamMembers8
  2. In the left-hand navigation click ‘Signing’.
  3. Check ‘Sign the assembly’
  4. Click the empty drop-down and then select ‘<New>’ which will allow us to create a certificate.
  5. I’d suggest filling in the values similar to the image below, make sure your password is memorable and secure.
    emailTeamMembers9
  6. Click OK and the certificate will be created.

Build the Project

  1. Save the project then click the ‘Build’ option in the menu at the top and click ‘Build Solution’.
  2. All going well you will see something along the lines of the text below in the Output window. If not you will need to either google the error it shows or comments below and I’ll try to help.
    emailTeamMembers5
  3. Copy the address shown right of the ‘EmailTeam -> ‘ text in the Output window up to the last backslash (\).
  4. Open a file explorer on your computer and paste it into the address bar at the top then hit enter on your keyboard to go to that location.
  5. You should be seeing 5 files if you’re in the right location. The most important one being called * nameOfYourProject*.dll, in my case it’s called EmailTeam.dll.

Registering your Custom Workflow Step

So by this point, you’ve created the project containing all the required code and you’ve built the .dll file that we will use with a tool called the ‘PluginRegistration’ tool that can be found in the CRM SDK folder. This will register the plugin with CRM and allow us to use it in workflows and the likes in CRM.

  1. To start, access the ‘Plugin Registration’ folder located in the CRM SDK folder.
  2. Then run the ‘PluginRegistration.exe’ file.
  3. Once the program opens you’ll need to click ‘Create new connection’ at which point you’ll need to fill in the details to connect to your deployment. In my case, I’m going to connect to an Internet-facing on-premise deployment so my details are as below –
    emailTeamMembers6
  4. Click Login, and you should see a list of registered plugins & custom workflow steps.
  5. Click ‘Register’ then ‘Register new Assembly’.
  6. The ‘Register New Assembly’ window will now open, we’ll want to set it up as follows in most circumstances –
    • Step 1 – Select the .dll file we created in one of the earlier stages
    • Step 2 – No change, leave all selected
    • Stage 3 – Check ‘Sandbox’ if not already checked
    • Step 4 – Select ‘Database’ if not already checked
  7. Finally, click ‘Register Selected Plugin’.
  8. All going well you will get a popup similar to below –
    emailTeamMembers10
  9. The plugin is now registered with CRM and can be used in workflows as a custom step.
  10. From here you can then make use of the process in a workflow

Using the Process

This process can be used by creating a workflow and then adding a ‘Create Email step, ensuring that you don’t add a value in the To field.

  1. Click ‘Add Step’ and then scroll down and select ‘CreateActivityParty (1.0.0.2)’ or similar.
  2. Then select ‘CreateActivityParty.CreateActivityPartyFromTeam’ which will allow us to generate an activity party (what goes in the To field of an email) and then send the email to all individuals in a team.
  3. In Team enter a link to a valid team, normally I do this personally by having populated an ‘Owner (Team)’ field on the record the workflow is associated to, this could be a case or anything with an owner.
  4. Enter a link to the related email record you created in the previous step and then click ‘Save and Close’
  5. Once the workflow runs it should then dynamically populate who the email is sent to based on the individual team members.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.