Nov 212011

Everybody loves to use InfoPath forms. And let’s face it, we all wish we could just take them and put them into CRM. What I’ve written is a simple way to do that without the hassle of figuring out how to bind the InfoPath form schema to a custom WCF service. It still doesn’t do everything I want it to, but it works, so I figured I’d go ahead and put it out there for everyone to look at, play with, and even use.

If you are interested in this solution, you can download the following:

  • Managed Solution (this is the only thing you need)
  • Unmanaged Solution (in case you want to modify mine, like add grid support, it is on my to-do list)
  • Source Code (this is in case you would prefer to use a WCF service or if you just want to play around with my code)

Once you’ve installed the managed solution, you’ll need to do the following to create / setup an InfoPath form:

  1. For this particular InfoPath integration, you need to create InfoPath Forms that mirror a CRM Entity.
    Note: You can always create a new entity for the form data.

  2. Rename the default form Group to the name of the entity (ex: Contact)

  3. Inside CRM create the InfoPath form (it is an entity included in the solution), select the entity and save the form.

  4. Once it has been saved, you can copy the ID using the “Copy ID” link in the header.

    Note: If you do not select the Allow Any CRM Field checkbox, you will need to add the individual Fields, which can be found in the left navigation.

  5. In the InfoPath Form Designer, add a field named SubmissionCode with the Default Value as the ID you just copied.

    Note: Using the submission code allows us to check and see if the form is valid, active, and allowed.

  6. Add a field for each of the fields in CRM that you want to be available, selecting the appropriate data type.

    Note: Unfortunately I have not had the time to test the fields and have been using the checkbox on the infopath form record to enable any/all CRM fields. However, I did not want to delay releasing the code and information as it currently is. If someone identifies a problem with this or any other section of the code, I’ll be happy to look into it and work on resolving the issue.

  7. Layout the fields on the form, then click File > Submit Options > To Email

  8. Enter the Queue email or where you want new forms to be submitted.

  9. Click Next.

  10. Click Finish.

  11. Save and close the form designer.
  12. Open the form and test submission.

Once the email comes into CRM, the process of reading the form is easy; you just open it up and click the Import InfoPath button on the ribbon.

Usually I would post the source-code and comment on how it works in great detail, but this time, it really depends on which component. There is a plugin and WCF service written in C# as well as two Jscript files, one for the buttons and one for the InfoPath form inside CRM that creates a drop-down of the entities in CRM. I would suggest downloading the unmanaged solution and source-code if you want to delve into those items.

Now, for complex situations or form conversions, binding the InfoPath schema is the way to go. Using that method (the one described in detail on Philo’s Weblog) you can import the InfoPath form schema into Visual Studio:

  1. Create an InfoPath form and lay it out the way you want it.
  2. Extract the form files (File | Extract Form Files) to a location you can find later.
  3. Close the InfoPath form designer.
  4. Open the Visual Studio command prompt.
  5. Change to the directory where you extracted the files
    cd c:\myinfopathfiles
  6. Run xsd against the myschema.xsd in that directory, and specify the namespace you would like to use.
    Note: My WCF namespace is CrmInfoPathService and my plugin namespace is InfoPathPlugin.
    xsd.exe myschema.xsd /classes /l:cs /n:InfoPathPlugin
  7. Then you can deserialize the xml into the object and store it in CRM or any other system using the logic embedded in your code.

The key point to my solution was not to do something that everyone does on occasion, but to make something so that I can leverage it in the future and not have to create a new integration every time I wanted to leverage a new form. Now, on that note, here are the list of things that if you delve into, I’d like to know, a.k.a. my to-do list for this project:

  • Add a button onto the grid for activities
  • Create a way to handle child entities.
  • Modify the plugin/WCF code to link the created entities to the form email using connections.
  • Change the button on the form to monitor for the results (success/failure) and report back to the user.
  • Any great ideas my readers think should be added!
May 162011

Just as an example to help people understand how you can leverage the SoundsLikePlugin, here is how to set it up for Account Name using Metaphone. You should pay attention to your config xml, which I posted in a previous article: SoundsLikePlugin: Soundex & Metaphone Plugin for CRM Online. You can leverage the plugin and duplication detection on other entities. You just need to adjust the configuration and steps accordingly for another entity and fields.

Create a Solution

  1. Create a Solution
  2. Add the Account as an existing entity
  3. Add two new fields, new_SoundexName and new_MetaphoneName and put them on the Account form as read-only
  4. Save and Publish all changes

Register the plugin assembly

The first step is to register the plugin assembly, to do that you will need to use the Plugin Registration Tool, which is included in the sdk (uncompiled).

Compiling the Plugin Registration Tool

  1. Open the solution, pluginregistration.sln in tools\pluginregistration folder inside the SDK with Visual Studio 2010
  2. Compile (Build) the solution
  3. Navigate to the tools\pluginregistration\bin\Debug folder in the SDK.
  4. Launch the Plugin Registration Tool by double-clicking the PluginRegistration.exe

Connecting to CRM Online or OnPremise

  1. Enter the Label, “CRM Online” for CRM Online for example
  2. Enter the discovery url. For CRM Online the discovery url is
    • If you have any problems authenticating, try deleting the %userprofile%\LiveDeviceID\LiveDevice.xml

  3. Select the Organization in the Connections in the left window pane

Registering the Assembly

  1. Click the Register button, then click Register New Assembly

  2. Click the … button in Step #1 and select the SoundsLikePlugin.dll file.

  3. Click Register Selected Plugins, then click Ok on the window that says they were successfully registered.

Register the Steps

  1. Select the Assembly, then click Register, then Register New Step

  2. Enter Create for the Message
  3. Enter account for the Primary Entity
  4. Enter your configuration xml
  5. Select Pre-Validation
  6. (Optional) Check the box for Offline Deployment
  7. Register the Step

  8. Select the Assembly again, then click Register, then Register New Step
  9. Enter Update for the Message
  10. Enter account for the Primary Entity
  11. Enter your configuration xml
  12. Click the three dots (…) for the filtering attributes field, make sure to check the checkbox for all of the source and target fields you specify in your configuration
  13. Select Pre-validation
  14. (Optional) Check the box for Offline Deployment
  15. Register the Step

Setup the Duplicate Detection Rule

  1. Click Settings, then Data Management, then Duplicate Detection Rules

  2. Click New to create a new duplicate detection rule
  3. Enter the Name: Account Name sounds like another account name
  4. Select the Base Record Type: Account
  5. Select the Field: Metaphone Name and the Criteria: Exact Match

  6. Save and Publish the rule

Create a Duplicate Detection Job

  1. Click Settings, then Data Management, then Duplicate Detection Jobs

  2. Click New to create a new Duplicate Detection Job
  3. Set it up according to your requirements
  4. Click Next
  5. Click Submit

Run the Duplicate Detection Job and View Duplicates

When the job runs, you can view the duplicates by going back to the Job and clicking View Duplicates

May 152011

In a previous comment and discussion on my blog and codeplex I was asked to convert the Metaphone and Soundex codification routies in the manipulation library to be plugins instead of custom workflow activities. And yesterday I finally got a chance to take the code from the manipulation library and tweak the metaphone and soundex classes to be used in a plugin. After about an hour of sporadically working on it while watching TV with my beautiful wife I had a version that was ready for testing. This afternoon I tested it, and it appears to be working properly, so I figured I’d go ahead and share it.

In response to requests I added a new project to the manipulation library on codeplex. The new project, SoundsLikePlugin, allows you to utilize soundex, soundex original, and my metaphone-like codification through a plugin for CRM Online and CRM 2011. The unsecure configuration contains the codification settings that specify the fields to encode, etc. It will work both Server side and Offline (with the Outlook client).

Here is an example configuration (config xml):

That configuration uses the name field and codifies it using 3 different methods to 3 different fields. The way the plugin is setup you can do however many soundex/metaphone codifications you need to on an entity.

The attributes in the codify element are very simple. There are 6 different attributes you can specify:

  • method:
    • Description: The method of codification soundex, soundex-original, and metaphone.
    • Default: The default method is metaphone.
  • source:
    • Description: The field that contains the string to codify
    • Default: The field called "name" – if the field does not exists, then the default won’t work
  • target:
    • Description: The target field in which to store the codified string
  • disable-manual-update:
    • Description: When true, it will prevent the target field from being set manually
    • Default: false
  • min:
    • Description: The minimum number of characters
    • Default: 0 (zero)
  • max:
    • Description: The maximum number of characters
    • Default: 6

To register the plugin you should first compile or download the plugin, use the plugin registration tool to register the assemby, and add the corresponding steps for the update and create messages on the entities with the configuration xml in the unsecured or secured configuration.

However, since there are a lot of people that read my blog that may not be experts at registering a plugin, I’ll go ahead and walk you through the entire process.

How to register and setup the SoundsLikePlugin:

  1. Download the SoundsLikePlugin.dll
  2. Follow the steps here to setup the Plugin Registration Tool (It is in the SDK – tools\pluginregistration)
    • The above link refers to an article written by Paul Reitmeyer. It has screenshots that may help you navigate how to use the plugin registration tool.
  3. Run the Plugin Registration Tool
  4. Connect to your Discovery Service
    • If you are using CRM Online, the discovery url is – if you have any problems authenticating, try deleting the %userprofile%\LiveDeviceID\LiveDevice.xml
  5. Select your organization on the left
  6. In the right pane, on the toolbar, click the Register button, then click Register New Assembly
  7. Click the three dots (…) in the top right of the window, then browse and select the SoundsLikePlugin.dll
  8. Make sure Step #3 has Sandbox selected and Step #4 has Database selected
  9. Click the Register Selected Plugins button
  10. Expand the assembly, click on (Plugin) SoundsLike.SoundsLikePlugin
  11. Click Register, then Register New Step
  12. Registering the Create/Update Steps:
    1. Enter Create in the Message Name
    2. Enter the entity in the Primary entity field
    3. Click the three dots (…) for the filtering attributes field, make sure to check the checkbox for all of the source and target fields you specify in your configuration
    4. Paste in a config xml into the unsecured configuration
    5. Select Pre-operation (CRM 2011 Only)
    6. Check the box for Server and Offline
    7. Click the Register New Step button
  13. Repeat the above section on registering the step for the Update message.
  14. Open CRM and test – you should always test

There you have it, a way to codify a text field using soundex, metaphone, or even the orginal soundex.

To quote Wikipedia:

Soundex was developed by Robert C. Russell and Margaret K. Odell and patented in 1918 and 1922. A variation called American Soundex was used in the 1930s for a retrospective analysis of the US censuses from 1890 through 1920. The Soundex code came to prominence in the 1960s when it was the subject of several articles in the Communications and Journal of the Association for Computing Machinery, and especially when described in Donald Knuth’s The Art of Computer Programming.

The National Archives and Records Administration (NARA) maintains the current rule set for the official implementation of Soundex used by the U.S. Government. These encoding rules are available from NARA, upon request, in the form of General Information Leaflet 55, “Using the Census Soundex”.

If you’re interested in SoundEx or Metaphone, I’d suggest reading up on it on Wikipedia. My metaphone algorithm is not an exact match, but I think it is close enought to do the job adequately. Over time changes have been made for slavic, germanic, etc. and some of those changes are incorporated in my version while some of them are not.