Microsoft Dynamics CRM and Add-in Express 2010
Microsoft Dynamics CRM (Customer Relationship Management) is quickly becoming one of the leading CRM Suites for midsized and large organizations according to a recent research report.
You might ask how this affects you as Office developer. Well, for one, Microsoft Dynamics CRM has a Microsoft Office Outlook client that installs an add-in for Outlook, giving users the ability to access and perform CRM specific tasks straight from Outlook.
In this post I’ll be showing you how you can further extend the functionality of the Dynamics CRM Outlook Client by using Add-in Express 2010 and MS Office Outlook 2010. For this example I’ve used a few of the Northwind customers and their associated contacts as sample data.
In this example ,I am using MS Dynamics CRM 4, with rollup 10 installed. The Outlook Add-in for Dynamics CRM is compatible with Office 2010, 2007 and 2003 SP3. You can read more about the MS Dynamics CRM Outlook Add-in here.
Once the CRM Outlook Client has been installed, it will create the CRM folder layout in Outlook:
When you click on a folder, the associated Dynamics CRM view will be displayed in Outlook:
The CRM Outlook Add-in accomplishes this by setting the folders’ Home Page to the CRM Contact view that is hosted on the CRM server:
Another really neat feature about the CRM Outlook Add-in is that it synchronizes the Contacts stored in CRM to your Outlook Contacts:
One catch, however, is that it only displays the basic contact information. If for example, you would like to see all the orders for a contact, you would have to navigate to the Contact folder or CRM web UI, open the contact and select Orders from the navigation menu. I’ll show you how you can give your users an integrated UI that will show all the contact orders directly from the Contact form in Outlook by using Add-in Express 2010.
First, create a new Add-in Express COM Add-in project in Visual Studio, select Microsoft Office 2010 as the minimum supported Office version and Microsoft Outlook as the supported application. Once the new project wizard has completed, add a new ADX Outlook Forms Manager component to the AddinModule designer. Next, add a new Outlook Form to your project.
Select the newly added Outlook Forms Manager component and click on the ellipses (…) button next to its Items property. Add a new FormsCollectionItem by clicking the Add button. Set the InspectorItemTypes property to Contact, the InspectorLayout property to InspectorRegion and the FormClassName property to the ADX Outlook Form you’ve added previously.
Next, open the Outlook Form and add a DataGridView and dock it in the Parent Container. We’ll use this grid to display all orders for the selected contact/customer. However, before we can display the orders on the Outlook Contacts form, we need to know to which CRM Account Id the contact is linked to. Open the Contact in Outlook and click on the All Fields button in the Show Ribbon Group and select “User-defined fields in this item” from the “Select from” dropdown list. You should see the following:
The Dynamics CRM Outlook add-in saves all the CRM information related to the contact in the UserProperties of the Contact Item.
Now that we have all the information in order to retrieve all orders, we can write the code to accomplish this. I’ve written a basic C# class that accepts an AccountId and returns a list of orders. The code listing is below:
public class Orders
{
public List AllOrders { get; set; }
public Orders(Guid accountId)
{
CrmService crmService = InitCRM();
this.AllOrders = new List();
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "customerid";
condition.Operator = ConditionOperator.Like;
condition.Values = new string[] { accountId.ToString() };
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions.Add(condition);
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.salesorder.ToString();
query.ColumnSet = new ColumnSet(new string[] { "ordernumber", "createdon","totalamount" });
query.Criteria = filter;
BusinessEntityCollection salesOrders = crmService.RetrieveMultiple(query);
foreach (BusinessEntity salesorder in salesOrders.BusinessEntities)
{
salesorder salesOrder = (salesorder)salesorder;
Order order = new Order
{
OrderNumber = salesOrder.ordernumber,
OrderDate = salesOrder.createdon.date,
TotalAmount = salesOrder.totalamount.formattedvalue
};
this.AllOrders.Add(order);
}
}
private CrmService InitCRM()
{
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "NorthwindTraders";
CrmService crmService = new CrmService();
crmService.Url = "https://:
/mscrmservices/2007/crmservice.asmx";
crmService.CrmAuthenticationTokenValue = token;
crmService.Credentials = new System.Net.NetworkCredential("", "
", "");
return crmService;
}
}
To keep things simple, we’re only returning the Order number, Created date and Total amount for the orders. Next, we’ll bind this class to the datagrid on our Outlook Form. Use the following code in the Outlook Forms’ Load event:
Outlook._Application OutlookApp;
if (OutlookAppObj != null)
{
OutlookApp = (Outlook._Application)this.OutlookAppObj;
Outlook.Inspector activeInspector = OutlookApp.ActiveInspector();
Outlook.ContactItem currentItem = (Outlook.ContactItem)activeInspector.CurrentItem;
Guid accountId=new Guid(currentItem.UserProperties.Find("crmParentAccountId").Value.ToString());
Orders customerOrders = new Orders(accountId);
this.dataGridView1.DataSource = customerOrders.AllOrders;
}
Build and register your project and start Outlook. Open a contact, and click on the right arrow. The result will be similar to the below screenshot.
And there you go! Your users can now see all the contacts orders without having to switch forms or applications.
Thank you for reading. Until next time, keep coding!
4 Comments
Pieter,
I just saw your blog entry on the integration with Microsoft CRM and just
wanted to let you know that we use Add-In-Express to integrate our Outlook
integration to many different CRM systems. We currently support Salesforce.cm, Microsoft CRM and SalesLogix and will be expanding to other CRM’s. Add-In-Express is a great product and your support is excellent. Keep up the good work.
Hi Glenn,
Thank you for the kind words!
A few more MS CRM related posts are coming up, so keep watching this space.
Kind Regards,
Pieter
Hi Pieter,
Great post.
My company is thinking about implementing CRM in-house and Im wondering where the CRM contacts are stored, will those contacts be available to other Exchange or Sharepoint users?
We currently store contacts in AD and is available to everyone with Exchange GAL.
If not, is there an API to create a synchronization program between Active Directory and MS CRM?
Best regards,
Steffen
Hi Steffen,
MS Dynamics CRM contacts are stored in the Dynamics CRM SQL database. You can use the Dynamics CRM Webservices/SDK ( https://www.microsoft.com/download/en/details.aspx?id=24004 ) to access contacts and create a synch app with Active Directory.
As far as I know you can use LDAP to run queries against AD, never used it myself. Check out https://technet.microsoft.com/en-us/library/aa996205%28EXCHG.65%29.aspx
Good luck and thanks for your comment.