Which Database Hotfixes Did I Just Install?

July 9, 2009 by Imad HAJJAR

This article will cover how to answer:

  • Which database hotfixes are currently installed on your Microsoft Dynamics CRM Server?
  • Which database hotfixes will be installed or uninstalled with a particular hotfix or Update Rollup (UR)?

Background

 

Historically, database hotfixes have been considered an internal detail of Microsoft Dynamics CRM hotfixes, so there is currently no straightforward way for administrators to track exactly when particular database hotfixes are installed or uninstalled.  There has been an increased interest in being able to track this information.  This article is intended to describe a workaround for deriving this information until a more formal means is available, most likely in CRM 5.0 timeframe.

All database hotfixes are cumulative.  Each new database hotfix will include all previously released database hotfixes as dependencies.  If a particular dependent database hotfix is already installed on your Server, it will not be reinstalled.  If a particular database hotfix is a dependency of other currently installed hotfixes, uninstall of the dependent hotfix will be a no-op.  It will be uninstalled when all other hotfixes that are dependent on it are also uninstalled.

No database hotfixes are installed when Microsoft Dynamics CRM Server is installed using the “Update installation files (strongly recommended)” option.  No database hotfixes are installed when a new organization database is created.  You must re-install database hotfixes for the new organization.

How to Track Database Hotfixes

You will need to know the KB numbers of the fixes you have already installed.  You can find this information in Add/Remove Programs.  For all of our examples, we will suppose that you have already installed the following:

  • KB949069
  • KB956129
  • KB955482

Example 1

Before installing Update Rollup 4 (KB968176), you want to know which database hotfixes will be installed along with it.

  1.  
    1. Download the UR 4 package and save it to your computer
    2. Extract the UR 4 package
      1. Click Start –> Command Prompt
      2. In the command prompt window type ‘<dir>\ CRMv4.0-KB968176-i386-Server-ENU.exe /X’, where <dir> is the location where you saved the UR 4 package and hit ENTER.
      3. In the “Choose Directory For Extracted Files” dialog enter the directory where you would like to save the extracted files; if it does not exist already, it will be created. Click OK.
    3. Find database hotfix install info in the extracted package
      1. In Windows Explorer, navigate to the directory where you saved the extracted files
      2. Open the language specific folder such as ‘EN’ for English
      3. Open the file dbhotfix_install.xml.  Do not modify this file, or any of the contents of the extracted package.

        UR 4’s dbhotfix_install.xml looks like this:

<releases>

<release version=”04.00.7333.1027” progress_range=”20” location=”KB948172\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1028” progress_range=”20” location=”KB948588\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1029” progress_range=”20” location=”KB951300\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1030” progress_range=”20” location=”KB950229\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1050” progress_range=”20” location=”KB952149\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1095” progress_range=”20” location=”KB956129\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1200” progress_range=”20” location=”KB953905\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1205” progress_range=”20” location=”KB954640\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1213” progress_range=”20” location=”KB957788\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1225” progress_range=”20” location=”KB949202\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1233” progress_range=”20” location=”KB957589\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1235” progress_range=”20” location=”KB955482\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1246” progress_range=”20” location=”KB956445\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1254” progress_range=”20” location=”KB960249\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1255” progress_range=”20” location=”KB949069\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1316” progress_range=”20” location=”KB959419\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1408” progress_range=”20” location=”KB961768\Install\DbHotfix_release.xml” />

<release version=”04.00.7333.1551” progress_range=”20” location=”KB968176\Install\DbHotfix_release.xml” />

</releases>

Each entry is a database hotfix – for ease of reading, I have highlighted the ones installed in our example. 

  • The location attribute indicates the KB number
  • The version attribute indicates the build number

Your server’s current build number will be the greatest version of all the hotfixes you have previously installed.  So in our example, your current build number is 04.00.7333.1255.

When you install a new hotfix, any entry with a version greater than your current build number will also be installed.  Any entry with a version less than or equal to your current build number is already installed, and will not be installed again.  So in the case of our example:

  • What is currently installed?
    • Every entry up to and including 04.00.7333.1255 (KB949069).
  • What will be installed when you install UR 4?
    • Every entry greater than 04.00.7333.1255, so in this case the last three entries: KB959419, KB961768 and KB968176.

Example 2

You want to uninstall KB949069.

We will uninstall as far back as the next greatest version number.  So in our example, that means we will go back to 04.00.7333.1235 (KB955482).  So KB949069, KB960249, and KB956445 will be uninstalled.

Example 3

You want to uninstall KB955482.

If you uninstall a database hotfix that has a version less than your current build number, it will not actually be uninstalled until you uninstall all hotfixes with a greater version number.  So when you uninstall KB955482, it will not be uninstalled until you also uninstall KB949069.

Example 4

You want to install or uninstall a KB that is not listed in dbhotfix_install.xml

If you have a KB that is not listed in this file, this is because no new database hotfix was released with it.  You can still derive database hotfix tracking information by using the build number of that hotfix. You can find the build number in the KB article.

Thanks,
Leslie Zavisca

RELEASE – White Paper v2: Optimizing and Maintaining Microsoft Dynamics CRM 4.0

July 9, 2009 by Imad HAJJAR

The MS CRM E2 team is pleased to announce the release of the version 2.0 update of the white paper Optimizing and Maintaining Microsoft Dynamics CRM 4.0, which is available from Microsoft Downloads at
https://www.microsoft.com/downloads/details.aspx?FamilyID=ba826cee-eddf-4d6e-842d-27fd654ed893&displayLang=en

Working with resources from Microsoft Premier Field Engineering, Microsoft SQL Server, UK MCS, and CRM Performance and UA teams, this update reflects the latest information available to assist readers with optimizing and maintaining the performance of Microsoft Dynamics CRM 4.0 implementations.

The following list provides a summary of the changes included with this version 2.0 update:

  • Updated hardware requirements for:
    • Microsoft Dynamics CRM 4.0
    • Microsoft Dynamics CRM 4.0 for Outlook
  • Categorized references/links to external content to by product version where appropriate (e.g. Windows Server 2003 and Windows Server 2008), and provided additional references where available
  • In the section Optimizing and Maintaining Internet Information Services, added the topic Optimizing the Performance of Integrated Windows Authentication and Kerberos Authentication
  • In the section Optimizing the Performance of Microsoft Dynamics CRM:
  • In the topic Enhancing Performance by Distributing Server Roles, added the sub-topic Considerations for Distributing Server Roles
  • In the topic Optimizing the Performance of Microsoft Dynamics CRM 4.0 Applications, in the sub-topic Optimizing the Performance of Microsoft Dynamics CRM Customizations, supplemented the information on disabling auto-complete on lookups with procedural information
    • In the section Optimizing Workflow, added multiple best practices.
    • In the section Optimizing and Maintaining Microsoft SQL Server and the Microsoft Dynamics CRM Database:
  • Added note about and reference to white paper Improving Microsoft Dynamics CRM Performance and Securing Data with Microsoft SQL Server 2008
  • In the topic Optimizing and Maintaining Query Performance, added the sub-topic Enhancing the Performance of the Display of Query Results
  • In the topic Optimizing and Maintaining the Microsoft Dynamics CRM Database, added the sub-topic Implementing Solid State Drive Technology
    • Added Appendix B: CRM Performance Counters; created Appendix C: CRM E-mail Router Performance Counters for previously published Appendix B content; added Appendix D: Summary of Changes in v2.0 Update

Cheers,

Jim Toland

Monitoring Microsoft Dynamics CRM 4.0 Queues with a Windows Sidebar Gadget

July 9, 2009 by Imad HAJJAR

Summary

Learn how to use Microsoft Windows Sidebar gadget to monitor the information that is contained in Microsoft Dynamics CRM queues.

The sample demonstrates how to write a custom application that uses SOAP messages to call Microsoft Dynamics CRM Web service APIs to retrieve the queue data.

Download the sample code for this article: CrmQueueGadget.

The Readme.doc that is included with the sample code contains information about how to install and run the sample application.

Applies To

Microsoft Dynamics CRM 4.0

Windows Vista

Introduction

Microsoft Dynamics CRM 4.0 contains a rich set of Web service APIs that can be used by various types of applications. This sample application uses a Windows Sidebar gadget to retrieve and display the information that is contained in the Microsoft Dynamics CRM 4.0 queues of a currently logged-in user. The polling of data is performed at specified time intervals. Because the Windows Sidebar gadget is always available on the computer desktop, it is a perfect tool for displaying information that is frequently updated. Monitoring the content of the Microsoft Dynamics CRM Assigned and In Progress queues with the CRM Queue gadget fits well into this category. The Assigned and In Progress queues contain work items that frequently change and often require your immediate attention.

Dd981046.Important(en-us,MSDN.10).gifImportant
It is important to become familiar with Windows Sidebar programming before you install and run the sample application. You can find the information at http://msdn.microsoft.com/en-us/library/aa965850.aspx.

Queues in Microsoft Dynamics CRM

Microsoft Dynamics CRM queues are holding containers for activities that have to be completed. You can use queues to manage your activities, such as tasks, e-mails, or telephone calls. You can also use queues to manage cases that are created to handle customer service issues. There are two types of default queues: Assigned and In Progress. The Assigned queue contains active cases and activities that have been assigned to you, but that you have not yet accepted. This can include e-mail messages that you have received. The In Progress queue contains cases and activities that you have accepted and that you currently are working on. Your organization may create additional queues.

Using CRM Queue Gadget to Display Queue Content

To view Assigned or In Progress work items, you have to specify the user settings information in the fields that are provided by the CRM Queue gadget. This information includes the Microsoft Dynamics CRM server name (required field), the organization name, polling interval and queue type. To display the content of a specific queue, select Assigned or In Progress in the Queue type drop-down list.

The user settings information.

Dd981046.cd5dbf3d-f0fe-45e9-84f2-27d280bc0f79(en-us,MSDN.10).png

The following work items are retrieved from the Assigned queue.

Dd981046.679e322b-3276-410c-a9fc-cf31c0a6c56d(en-us,MSDN.10).png

The following work items are retrieved from the In Progress queue.

Dd981046.4d2be854-1838-41cb-bf0c-b4c6f623b00c(en-us,MSDN.10).png

The Microsoft Dynamics CRM Queues form displaying work items that are contained in the In Progress queue.

Dd981046.7f6b4ea6-d8a9-4e62-8943-99691b84bc11(en-us,MSDN.10).png

Developing the CRM Queue Gadget Application

The following sections describe how to retrieve the data from the Microsoft Dynamics CRM queues by using SOAP messages and how to read and write the user settings data.

Retrieving Data from Microsoft Dynamics CRM

Windows Sidebar Gadgets are composed of HTML and JavaScript files. You can use an AJAX object in JavaScript to send custom SOAP request messages to the Microsoft Dynamics CRM server. To parse the response to SOAP request messages, use the Msxml2.DOMDocument DOM object. You do not have to process the SOAP messages asynchronously because the user is not blocked by the gadget application. To reduce the server load, retrieve only important information that you want to monitor.

The following code example shows how to build the SOAP request to retrieve the queue items and process the response.

JScript
// Create a RetrieveMultiple message request and receive a response 
// from the Microsoft Dynamics CRM server.
function getQueueItems(queueId)
{
    // Build the SOAP request for the RetrieveMultiple call.
    var request = '<soap:Body><RetrieveMultiple xmlns="http://schemas.microsoft.com/crm/2007/WebServices">';
    request += '<query xmlns:q1="http://schemas.microsoft.com/crm/2006/Query" xsi:type="q1:QueryByAttribute">';
    request += '<q1:EntityName>queueitem</q1:EntityName>';
    request += '<q1:ColumnSet xsi:type="q1:ColumnSet">';
    request += '<q1:Attributes>';
    request += '<q1:Attribute>title</q1:Attribute>';
    request += '<q1:Attribute>objectid</q1:Attribute>';
    request += '<q1:Attribute>objecttypecode</q1:Attribute>';
    request += '<q1:Attribute>priority</q1:Attribute>';
    request += '</q1:Attributes>';
    request += '</q1:ColumnSet>';
    request += '<q1:Attributes>';
    request += '<q1:Attribute>queueid</q1:Attribute>';
    request += '</q1:Attributes>';
    request += '<q1:Values>';
    request += '<q1:Value xmlns:q2="http://microsoft.com/wsdl/types/" xsi:type="q2:guid">' + queueId +'</q1:Value>';
    request += '</q1:Values>';
    request += '<q1:PageInfo>';
    request += '<q1:PageNumber>1</q1:PageNumber>';
    request += '<q1:Count>5</q1:Count>';
    request += '</q1:PageInfo>';
    request += '<q1:Orders>';
    request += '<q1:Order>';
    request += '<q1:AttributeName>enteredon</q1:AttributeName>';
    request += '<q1:OrderType>Descending</q1:OrderType>';
    request += '</q1:Order>';
    request += '</q1:Orders>';
    request += '</query>';
    request += '</RetrieveMultiple></soap:Body>';

    // Execute the RetrieveMultiple request.
    var response = executeRequest(request, "RetrieveMultiple");

    // Load the response XML into a DOM object.
    var oXml = loadXml(response);

    // Retrieve the business entities that are contained in the queue.
    var queueItems = oXml.documentElement.selectNodes("//soap:Body/RetrieveMultipleResponse/RetrieveMultipleResult/BusinessEntities/BusinessEntity");

    return queueItems;

Reading and Writing User Settings Using the Gadget Infrastructure

The gadget infrastructure provides APIs for reading and writing the user settings, such as the Microsoft Dynamics CRM server name, the polling interval, and the queue type.

The following code example shows how to read the user settings.

JScript
var currentServerName = System.Gadget.Settings.readString("crmServerName");

The following code example shows how to write the user settings.

JScript
var temp = serverName.value;
System.Gadget.Settings.writeString("crmServerName", temp);

Additional Information

Inna Agranov
Microsoft Corporation

June 2009

New Silverlight 2 Sample on Code Gallery

July 9, 2009 by Imad HAJJAR

I recently did an investigation into using Silverlight 2 with Microsoft CRM 4.0. I have posted the resulting project and supporting documentation on Code Gallery. See Microsoft Dynamics CRM 4.0 On Premise Silverlight 2 Bar Chart Sample.

Unlike many code samples you may find, this one includes full step-by-step instructions about building and deploying the sample. It is more like a hands-on-lab. This sample leverages the work done by Humberto Lezama Guadarrama in his post Sample:Silverlight 2 and CRM.

This sample explores the following tasks:

  • Using the Asynchronous methods required by Silverlight
  • Establishing CRM Authentication
  • Using Silverlight Toolkit Chart controls

Using the Asynchronous methods required by Silverlight

One of the things this sample explores is how to use the proxy generated by Visual Studio 2008 for Microsoft CRM 4.0 web services. This is a bit complicated because Silverlight doesn’t allow for synchronous Web service calls – and the Microsoft CRM SDK doesn’t document the use of asynchronous web services calls. When you create the reference to the Web service in Visual Studio 2008 you don’t get a standard CrmService object, you get a CrmServiceSoapClient object which only exposes the asynchronous messages.

Testing indicates that with one notable exception the asynchronous versions of the methods appear to work as expected. One known problem is that the RetrieveMultipleAsync method may return null values. The work around for this is to use the ExecuteAsync method on an RetrieveMultipleRequest that is configured to return Dynamic Entities. This sample shows how this works.

Establishing CRM Authentication

As detailed in Humberto Lezama Guadarrama’s post Silverlight 2 and CRM, it is necessary to provide a mechanism to inject a custom CRM Authentication token into the SOAP headers generated by the proxy. This sample uses the same technique.

Using Silverlight Toolkit Chart controls

Finally, when creating this sample I was looking for a way to use Silverlight within Microsoft CRM without writing a complete CRM UI. The Silverlight Toolkit provides some useful components to build charts. Since these could be hosted within a CRM IFrame or launched like a report from a custom button – I chose to use those.

If you are interested in trying Silverlight in the context of Microsoft CRM, I hope this sample helps you.

Cheers

Jim Daly

Synchronizing and the Offline Client

July 3, 2009 by Imad HAJJAR

One of the great features provided by Microsoft Dynamics CRM Online is the ability to take the application offline (i.e. work on a plane).  This capability is made possible by our S+S (software+services) vision of leveraging the best of services (CRM Online) coupled with the best of software (Outlook).  This is not possible in a SaaS (software as a service) model as locally installed software is required to achieve the functionality since an internet connection would not be available to serve up the hosted service.  The offline CRM Outlook client functionality is made possible by utilizing Outlook, a SQL Express database to store the offline CRM data and IIS on the laptop to render the web pages.  This is a competitive advantage of the Microsoft CRM offering that many of our competitors do not offer or are trying to replicate (thus proving the efficacy of the S+S vision).

Recently I was asked the following question:

“When I go Offline with the Outlook client and create a CRM Appointment, will it show up on my Outlook calendar?”

This was a question I recently received from one of our customers.  I believed the answer was yes but I wanted to investigate and take the scenario a bit further to include the core synchronization elements (Appointments, Contacts and Tasks).  So to test I:

  1. Installed the Offline Outlook Client.  There is only 1 Outlook client that supports both subscriptions (Professional – No Offline and Professional Plus – Offline).  In order to achieve the Offline capabilities you must select to install Outlook with Offline Access during the installation process.
    Online or Offline installation option
    NOTE: If you have the Outlook Client installed and upgrade your CRM Online subscription to Professional Plus you will need to uninstall and reinstall the Outlook Client in order to gain the offline functionality.  This WILL NOT delete any of the records previously synchronized with CRM and upon reinstall will maintain the CRM and Outlook record linkage.
  2. Went offline but clicking on the Go Offline button in the CRM toolbar.
  3. Created a CRM Appointment.
    CRM Appointment Created while Offline
  4. Confirmed the synchronization of the CRM Appointment to the offline Outlook Calendar.
    Confirmation of Outlook Appointment created while Offline
  5. Created a CRM Contact
    CRM Contact created while Offline
  6. Confirmed the synchronization of the CRM Contact to the offline Outlook Contacts.
    Confirmation of Outlook Contact created while Offline
  7. Created a CRM Task.
    CRM Task creation while Offline
  8. Confirmed the synchronization of the CRM Task to the offline Outlook Task.
    Confirmation of Outlook Task created while Offline
  9. Created a CRM Appointment in the CRM web client.
    Appointment created in web client while Outlook is offline
  10. Confirmed the Appointment created in CRM Offline has not synchronized to the web database.
    Confirmation that Offline Outlook Appointment does not exist in CRM Online (web) database
  11. Confirmed that the Appointment created in the CRM web client did not synchronize to the Offline Outlook client (only appt. created in step 3 exists).  Synchronized Outlook and CRM by clicking on the Go Online button in the CRM toolbar.
    Confirmation that webclient Appointment does not exist in Outlook.  Synchronizing changes made to offline and web client
  12. Confirmed the Offline created CRM Appointment and CRM Task were synchronized to the CRM web database.
    Task created while Offline now exists in CRM webclient.
  13. Confirmed the Online created Appointment was synchronized to the Outlook client.
    Appointment created while Offline now exists in CRM webclient.

Hopefully this will help you get a better understanding of how the offline synchronization process works with the Microsoft Dynamics CRM Outlook client.

Cheers,

Eric Boocock

Microsoft Dynamics CRM 4.0 IWorkflowContext Interface

July 3, 2009 by Imad HAJJAR

The IWorkflowContext interface is the interface that is used to provide a way to obtain business data that is needed to correctly implement your business logic in a custom workflow activity.

In order to start we first need to understand how the IWorkflowContext is initialized.

Where does the IWorkflowContext come from?

The IWorkflowContext is initialized for a particular asyncoperation of type workflow (operationtype 10) when the asyncoperation of type workflow is processed and executed by the Asynchronous Service. However that is only where the context object is created. The data that is contained in the context object was collected prior to this action.

The Workflow Expansion Task plugin executes asynchronously for a particular message in CRM. For example if you have published a workflow to execute on Create of account, the Workflow Expansion Task plugin will be registered as a step on the Create message for the account entity when the workflow is published. The step will execute asynchronously. The Workflow Expansion Task plugin will retrieve all workflow rules that are published and that are configured to execute when the current message executes. So if you have more than one workflow that is published and should execute on the create message, the primary entity for the workflow is account, and you have access to the workflow based on the scope setting, those workflows will be retrieved.

The Workflow Expansion Task plugin will loop over each of the workflows retrieved and create an asyncoperation with an operationtype of 10 (Workflow). When the asyncoperation is created certain attributes are populated so that when the asyncoperation is processed by the Asynchronous Service it knows how to process the record. One of the attributes that is populated is the data attribute. In the SDK documentation the data attribute is a string property. The data property contains one of two types of serialized objects

AsyncOperationData

WorkflowData

Since we are working with an asyncoperation record of type workflow, the object is a WorkflowData object. When the asyncoperation is processed and executed by the Asynchronous Service, this WorkflowData object will be the basis of the IWorkflowContext object that we will have access to in our custom workflow activity.

Now that we know where the IWorkflowContext comes from, let’s look at how we can get access to the interface

How to get the IWorkflowContext object

The IWorkflowContext object can be obtained through the IContextService interface. Great, another interface! How do you get the IContextService interface??? Simple, we can obtain the IContextService interface through the GetService method on the ActivityExecutionContext which is provided as a parameter in our overridden Execute method for our custom workflow activity.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService ));

 

Now that we have our IContextService interface, we can now access the Context property which is of type IWorkflowContext.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService ));

 

IWorkflowContext context = contextService.Context;

 

Now that we know how to get the IWorkflowContext we can now look at what data it can provide

Great, we have the IWorkflowContext! Now what can we do with it?

In order to see what we have access to through the IWorkflowContext we can view the definition of it in Visual Studio by right-clicking IWorkflowContext, then clicking “Go To Definition”. When we do this we see the following

public interface IWorkflowContext

{

Guid ActivationId { get; }

Guid AsyncOperationId { get; }

Collection<EntityDependencyBase> EntityDependencies { get; }

PropertyBag InputParameters { get; }

string MessageName { get; }

Guid OrganizationId { get; }

PropertyBag OutputParameters { get; }

Guid PluginTypeId { get; }

Guid PrimaryEntityId { get; }

DynamicEntity PrimaryEntityImage { get; }

string PrimaryEntityName { get; }

DynamicEntity PrimaryEntityPostImage { get; }

DynamicEntity PrimaryEntityPreImage { get; }

PropertyBag SharedVariables { get; }

string StageName { get; }

Guid UserId { get; }

 

ICrmService CreateCrmService();

ICrmService CreateCrmService(bool asAdminUser);

IMetadataService CreateMetadataService();

IMetadataService CreateMetadataService(bool asAdminUser);

bool EvaluateCondition(ConditionOperator op, object primaryValue, params object[] values);

object EvaluateExpression(ExpressionOperator op, params object[] values);

void PopulateEntitiesFrom(CrmWorkflow workflow, string parameterName);

int RetrieveActivityCount(bool includeActivitiesCreatedByWorkflow);

}

Let’s go over each member in this interface
Properties

ActivationId: This is the workflowid for the workflowbase record that is the activation record for the workflow. In other words, this describes which workflow this is an instance of.

AsyncOperationId: This is the ID of the asyncoperationbase record.

EntityDependencies: This is a generic collection of EntityDependencyBase objects. An EntityDependencyBase object can be of one of the following types

PrimaryEntityDependency: Specifies the objectTypeCode (Int32), comma delimited attributes to retrieve for the primary entity (String), and the type of parameter it is (Type)

RelatedEntityDependency: Specifies the objectTypeCode (Int32), comma delimited attributes to retrieve for a related entity (String), and the type of parameter it is (Type)

You are going to have 1 PrimaryEntityDependency, and X RelatedEntityDependencies.

InputParameters: InputParameters is a property bag which contains the objects from the request that triggered the workflow. For example, if the workflow executed due to a create message for account, the InputParameters property bag would contain the target account as a DynamicEntity. You access the objects in the property bag just as you would when using a plugin.

MessageName: The name of the message which triggered the workflow to execute. Create, Delete, Update, or SetState.

OrganizationId: The ID of the organization to which this asyncoperation belongs

OutputParameters: OutputParameters is exactly the same as InputParameters. It contains the output of the request. For create, it would contain the GUID of the business entity created.

PluginTypeId: The ID of the plugin type. This is the ID for the compiled Windows Workflow that this asyncoperation is an instance of.

PrimaryEntityImage: A DynamicEntity object that represents the primary business entity for which the workflow is regarding. If you want to get attributes included in the create or update request, you don’t want to use this. Instead get the Target property out of the InputParameters property bag

PrimaryEntityName: The schema name for the entity that this workflow is regarding.

PrimaryEntityPostImage: DynamicEntity which contains the primary entity’s ID attribute along with the values for the attributes defined in the PrimaryEntityDependency after the operation which triggered the workflow to execute. This is not specific to a singular workflow, but contains all the needed attributes for all workflows registered to execute on the same message for the same entity type.

PrimaryEntityPreImage: DynamicEntity which contains the primary entity’s ID attribute along with the values for the attributes defined in the PrimaryEntityDependency after the operation which triggered the workflow to execute. This is not specific to a singular workflow, but contains all the needed attributes for all workflows registered to execute on the same message for the same entity type.

SharedVariables: Another property bag in which you can store data to be persisted to the database for use through-out the execution of the workflow. Also SharedVariables will contain any objects that have been stored in the SharedVariables property bag from the plugin execution context during the entire life of the pipeline for the message which triggered the workflow to execute. So you could store an object in the SharedVariables property bag pre create of an account, and that object would be available in any workflows that were created on create of the account.

Note: The IWorkflowContext’s SharedVariables property gets populated from the SharedVariables property on the IPluginExecutionContext for the “Workflow Expansion Task” asynchronous plugin. The “Workflow Expansion Task” executes in the Child pipeline. So if you want values from before the main operation (BeforeMainOperationOutsideTransaction) you need to register your Pre plugin step in the Child pipeline as well. Further, any SharedVariables you populate after the main operation (AfterMainOperationOutsideTransaction) will not be included even if you register your Post plugin step in the Child pipeline since the “Workflow Expansion Task” executes in the pipeline stage that is not available to third parties (AfterMainOperationInsideTransaction).

StageName: The name of the stage that workflow is currently in.

UserId: If the workflow was executed on demand, this will be the ID of the user who executed the workflow. If the workflow was executed due to a message executing, then it will be the ID of the workflow owner.

Methods

CreateCrmService:

CreateCrmService(bool asAdminUser):

Both of these methods return an ICrmService interface. This is optimal way to interact with CRM to execute the various requests in the CRM web service. The overload allows you to execute with more privileges if needed; just in case the current user doesn’t have the required privileges to perform some action in your custom business logic.

CreateMetadataService():

CreateMetadataService(bool asAdminUser):

Both of these methods return an IMetadataService interface. This is optimal way to interact with CRM to execute the various requests in the MetadataService web service. The overload allows you to execute with more privileges if needed; just in case the current user doesn’t have the required privileges to perform some action in your custom business logic.

RetrieveActivityCount: Retrieves the number of CRM activity records created so far by this workflow

The following methods are for internal use only and are not intended for third party use

EvaluateCondition(ConditionOperator op, object primaryValue, params object[] values):

EvaluateExpression(ExpressionOperator op, params object[] values):

PopulateEntitiesFrom(CrmWorkflow workflow, string parameterName):

Cheers,

Clint Warriner

How to toggle Smart Matching in Microsoft Dynamics CRM 4.0

June 24, 2009 by Imad HAJJAR

Smart matching is the default and the only email correlation strategy shipped with CRM 4. Smart matching uses the subject of the current email along with the email recipients of the current email and generates subject hash and address recipient hash and uses these hashes to compare against old emails to find a match for the subject hash and at least HashMinAddressCount number of address recipients to correlate with an old email. HashMinAddressCount is reg key based and has a default value of 2. Smart Matching is not always the solution that customers are looking for.

Read more about Smart Matching.

How Smart matching works

In cases we have emails that have same subject and atleast 2 (HashMinAddressCount) recipients that match, we treat this as a correlation and set the same regarding object for the new email to the old email which may not be right.

An example can be a Service based CRM setup might have Service Details in the subject and this email is sent to customer service representative and the case is related to customer Bob and there could be a second email that is addressed to the same CSRs with the same subject line but belongs to Customer John Doe. In this case Smart matching wrongly ties these 2 emails together.

Another scenario could be a case where HR sends a New Hire subject line email to a Manager and each email could be related to a different new Hire but Smart Matching will go wrong in this case.

In all these cases, users will have to use caution and always generate unique email subjects to avoid these wrong correlation problems which cannot be that feasible and hence the reason for choosing Tracking Token strategy used in V3 where the token is automatically generated and appended to the subject and emails are now correlated based on the tracking token only.

How to use the tracking token-based solution

1. There is a trackingtoken column that is indexed in EmailBase table that is used for correlating new emails with old emails when using the Tracking Token strategy instead of the Smart Matching strategy. This column is not filled for all emails in CRM v4 as we use Smart matching.

To get this tracking token column populated for the past emails in the database, please use the tool that comes with hotfix KB# 969946 that uses SQL CLR to use the power of regular expressions which are lacking in SQL Server but are available and are used by the CRM Server code to extract the tracking token out of the subject of the past emails in an efficient manner.

For this tool to work correctly in case CRM Server and SQL Server box are different, please make sure to set up same directory structure where the tool got dropped on the CRM Server in the SQL Server box as well. The reason being , the DB Scripts in the Tool install the assembly EmailTrackingTokenExtractor in the SQL Server and creates a user defined function in SQL Server that links to the external assembly function and hence SQL Server looks for this assembly on the SQL Server box.

if CRM is 32bit, and SQL is 64bit you will need both the 32bit Hotfix as well as the 64bit Hotfix. The 32bit dll and the exe must be placed on the CRM server, and the 64bit dll must be placed in the same path but on the SQL server. We found that when SQL is 64bit and you attempt to execute a SQL CLR type from a 32bit assembly you will get an error.

This tool uses the same regular expressions that the CRM server code uses to extract the tokens and so it honors all the different tracking token prefixes and other tracking token settings set in the past.

Once you have the tool extract all the tracking tokens from the subject and populate the tracking token column in the email base you are ready to enable tracking token strategy.

The tool has to run at a time when there is no activity (to reduce the contention on Email table and also not have a flood of emails in between) and once the tool run is complete, the hot fix can be installed and smart matching can be disabled. There is a chance that you might have some emails in that small delta of time so you can re-run the tool again to cover these emails if needed.

Without the power of SQL CLR we would have been forced to retrieve all the emails from the database and process them through the regular expressions in C# layer and bulk update these rows back to the database.

With the power of SQL CLR we can run updates as simple as:

update email set trackingtoken = dbo.ExtractToken(subject)

where trackingtoken is null

and subject is not null

and subject <> ”

where dbo.ExtractToken is a User defined function that refers to the C# function EmailTrackingTokenExtractor.[EmailTrackingTokenExtractor.TrackingTokenExtractor].ExtractToken which is defined in the EmailTrackingTokenExtractor.dll and is now installed in SQL Server.

This eliminates all the round trips between the mid-tier and SQL Server and all the processing including the regular expression processing is happening on SQL Server itself.

2. Follow the instructions of Knowledge Base article KB 958084 and set the DisableSmartMatching registry key to 1 to turn off smart matching after installing KB 958084 hotfix.

For this hotfix to work, please make sure that this registry key DisableSmartMatching is set to 1 and the Use Tracking Token option is set in the Settings. This will direct CRM email tracking manager to correlate emails using the tracking token (CRM V3 strategy) instead of the default CRM v4 Smart matching strategy.

There is no impact to switch back to Smart matching as we still store the address hashes and the subject hashes.

Cheers,

Chandra Akkiraju

Tapping into the Power of Workflows

June 23, 2009 by Imad HAJJAR

The workflow engine in Microsoft Dynamics CRM is an area I personally spend a ton of time playing with. It is like Jscript was in Version 1.x and 3.0 for me. It has A TON of potential that many people have barely scratched the surface of.

So in working with a customer over the past month, they wanted to track the number of widgets each one of their accounts has at each location. This works well, until they want to be able to run some queries and there is no way to be able to get the total number of widgets per account. How many accounts have brand A of widgets in a quantity of over 200? How many have Brand B?

So that is where workflow comes in. In talking with Jon Goodwin from Microsoft Consulting Services, he showed me a quick and easy way to have workflow create a summary number on a parent entity. So he showed me a quick trick to be able to take quantities from a child entity and using workflow, create a summary of the number of widgets owned.

Step 1. Create Widget Entity. Add a Quantity Owned to Widget Entity. In addition, I also wanted to track by competitor, but that step isn’t used in this example. Then create a field to track number of widgets and type of widget.

Step 2: Create N:1 Relationship Between Widget and Account Entities. (So the Widgets are a Child Record of an Account)

Step 3: Create Summary Field on Account. (To hold how many widgets total you have!)

Step 4: Create Workflow on Widget Entity. You will want the workflow to fire on the create of a Widget as well as the change of the number of widgets.

clip_image002

Add a step with the type of Update Record. Select Account as the Entity to update.

If you are anything like me, you generally close the form assistant. But in this case, we want to leave the form assistant open. We should click on the Total Number of Widgets, Make the Operator Increment By, and Look for Widget and Number of Widgets. In the Default Value, we put a 0 so that if the user creates the entity and doesn’t fill it in, it doesn’t inflate the total count.

clip_image004

Save and Close the Workflow and Publish it.

So here is the finished product:

clip_image006

And if I browse to Widgets, you can see that we do in fact have 1011 widgets in this location for this customer.

clip_image007

So there is one more way that Workflow can make CRM work better for your customers. Attached is the workflow rule if you want to play with in your demo or testing environment.

Happy Workflowing!

Ben Vollmer

Fetch It Part 2

June 19, 2009 by Imad HAJJAR

In the first blog on using Fetch XML, I introduced a tool that I had created that would allow you to execute Fetch XML statements to retrieve CRM data. In this blog, I want to discuss some of the inner workings to executing Fetch XML statements to retrieve more than a single page of records. Here’s the link to the updated FetchIt tool

The mechanism is a paging cookie that tells the CRM system were to start the retrieve from. The paging cookie is returned on a fetch execute statement in the data set. The first step is to execute a fetch xml request. This is pretty simple and documented well in the SDK.

string QueryString = @”<fetch mapping=’logical’><entity name=’new_test’><all-attributes/></entity></fetch>”;
Result = this.m_crmService.Fetch(QueryString);

 

 

This will return a string of xml data.

<resultset morerecords=”1″ paging-cookie=”&lt;cookie page=&quot;1&quot;&gt;&lt;new_testid last=&quot;{C855BD56-D955-DE11-90B3-001E0B5E0BF6}&quot; first=&quot;{37F4AB96-D755-DE11-90B3-001E0B5E0BF6}&quot; /&gt;&lt;/cookie&gt;”><result>……

Notice in the root element are the attributes morerecords and paging-cookie.

The morerecords indicates there is more data from the query. The limit per retrieve is 5000 records. To get more, you simply need to add the paging cookie to the next request.

string QueryString = @”<fetch mapping=’logical’ page=’2′ count=’5000′ ” + Cookie + “><entity name=’new_test’><all-attributes/></entity></fetch>”;

 

 

To accomplish this you’ll need to do a bit of parsing and string manipulation. Make sure you grab the quote on the end.

 

 

string Cookie= paging-cookie=”&lt;cookie page=&quot;1&quot;&gt;&lt;new_testid last=&quot;{C855BD56-D955-DE11-90B3-001E0B5E0BF6}&quot; first=&quot;{37F4AB96-D755-DE11-90B3-001E0B5E0BF6}&quot; /&gt;&lt;/cookie&gt;”

 

 

then insert into the query along with a paging attribute.

string QueryString2 = @”<fetch mapping=’logical’ page=’2′ count=’5000′” + Cookie + “’><entity name=’new_test’><all-attributes/></entity></fetch>”;

 

 

Next, all you need to is execute the fetch request with the new string. On each call, increase the page number from the last until morerecords = 0.

Here’s some code snippets. Make sure you add appropriate error handling. I put this together as a conceptual example.

 

 

string GetCookie(int idx,string DataChunk)

 

 

{

 

 

    int end = DataChunk.IndexOf(”>”, idx);

 

 

    int start = DataChunk.IndexOf(”paging-cookie=”);

 

 

    int nCnt = end – start;

 

 

    string Cookie = DataChunk.Substring(start, nCnt);

 

 

    return Cookie;

 

 

}

 

 

 

 

 

public static string InsertCookie(string fetchXml,

                     int PageNum, string Cookie)

 

 

{

 

 

    string Root = “<fetch mapping=’logical’ page=’”

     + PageNum.ToString() + “‘ count=’5000′ “

     + Cookie + “>”;

 

 

 

 

 

    int end = fetchXml.IndexOf(”>”);

 

 

    if (end < 0)

 

 

    {

 

 

      return “”;  // need to handle empty string

    }

 

 

 

 

 

    StringBuilder builder

            = new StringBuilder(fetchXml);

 

 

    int RootEnd = fetchXml.IndexOf(“>”);

 

 

    if (RootEnd > -1)

 

 

    {

 

 

        int length = RootEnd + 1;

 

 

 

 

 

        // Remove old root attributes.

 

 

        builder.Remove(0, length);

 

 

       

 

 

        // Insert new root element attributes

        builder.Insert(0, Root);

 

 

    }

 

 

  

 

 

    return builder.ToString();

 

 

}

 

 

 

 

 

 

cheers

-jonw

 

Posted: Wednesday, June 17, 2009 5:30 PM by JonWhite | 1 Comments

Enhanced Internet Lead Capture capabilities now available

For those currently using the Internet Lead Capture capabilities within CRM Online you may have noticed that the functionality was enhanced recently. 

Here are some highlights of what has improved:

- Canadian customers can now take advantage of Internet Lead Capture (AdCenter integration does not apply in Canada)

- There is support for vanity URLs which allows you to leverage your unique CRM Online org name for a specific landing page URL if you decide to have Microsoft host your internet lead capture page

- You have the ability to add any lead field (including custom lead fields) to the Internet Lead Capture web form

- There is an improved Lead Capture Home Page with embedded charts to show lead capture effectiveness

If you aren’t using this functionality today, you can easily activate it by clicking on “Landing Pages” or “Internet Leads” from the Sales or Marketing Tab within the left navigation

Performance counters for Microsoft Dynamics CRM 4.0

June 19, 2009 by Imad HAJJAR

Microsoft Windows operating systems include a tool named Reliability and Performance Monitor (or Performance Monitor in some versions of the operating system). You can configure this tool to obtain and display performance data as system components run on your Microsoft Dynamics CRM deployment.

Performance objects provide sets of counters that generate data about how various components perform as they run in your Microsoft Dynamics CRM environment. For example, the Processor object collects metrics that show how one or more microprocessors are performing on a particular server.

Many performance objects are built into the operating system, and more are installed with software applications and services. For example, the performance objects installed with SQL Server and Exchange Server can help you monitor the performance of components that are relevant to your system.

This article describes the performance objects and counters that are installed with Microsoft Dynamics CRM.

Read more…

Cheers,

Michael Guthmann