Saturday, September 11, 2010

Creating a MS CRM 2011 VM Part 1 of 2

I needed both a demo box and development environment to run on Win7 64 bit computers to show customers and to write code against the MS CRM 2011 beta using the SharePoint 2010 connectivity and Visual Studio 2010 to write WP7 applications against the new WCF services in MS CRM.

The new SharePoint List Connectivity in MS CRM 2011 is a feature a number of my customers are interested in and I expect to have a lot more CRM/SharePoint integration projects coming up. Assuming this is an indication of a general interest, this would be a great time to start learning SharePoint if you haven’t already so I consider this an important piece to build into this VM.

Two points:

  1. The world is going 64bit everywhere. There is no point trying to set up a 32bit box. It is time to just say no to 32 bit.
  2. Virtual PC doesn’t support 64bit applications which effectively makes it useless!

Options to Host a Virtual machine in Windows 7 64 bit

  1. Virtual Server on a W7 box as shown here (unsupported by MS)http://tfl09.blogspot.com/2009/08/windows-7-and-virtual-server.html
  2. VMware http://www.vmware.com/
  3. VirtualBox  http://www.virtualbox.org/wiki/Downloads

I chose Virtual Box 3.2.8 based on many recommendations. It can run 64bit VHD’s and VMWare VMs but will create a VDI file and it’s a free open source solution.

image

VirtualBox installation in Windows 7 64bit

  1. Stop IP Helper Service ( this will keep the VBox installation from working)
  2. Install VirtualBox from the downloaded exe. VirtualBox-3.2.8-64453-Win.exe

image

What you need before beginning to build your VM:

  • Time: Expect at least a full day to get everything set up and that’s on a reasonably fast system. My host system ( i7 12Gb RAM running the VM image off of RAID 0 10,000rpm drives, (VM 6Gb RAM, and 4 cores)) took a full day. Plan accordingly!
  • Windows 2008 R2 64 bit iso image
  • SQL Server 2008 R2 64 bit iso image (recent copy 5/3/2010) 
    • Note: Older SQL iso files may require SQL Server 2008 R2 SP1 and the following Hot Fix SQL Server SP1 Cumulative Update 2 http://support.microsoft.com/kb/970315/
    • They will give you this error message during the SharePoint Installation.
      image
    • Save yourself the trouble and download the latest SQL 2008 R2
  • SharePoint Server 2010 64 bit iso image
  • VS 2010 iso image

The current CRM 2011 beta downloads are here you will need the following:

  • MS CRM 2011 Server CRM2011-server-ENU-amd64.exe
  • CRM2011-SharePointList-ENU-amd64.exe
  • MicrosoftDynamicsCRM2011BetaSDK.exe

Credit where credit is due:

I am going to defer to the good work of the folks at Critical Path Training for their excellent instructions and links to video for setting up a SharePoint 2010 VM, so please visit their site http://www.criticalpathtraining.com create an account (it’s free), then go to the Members Section and download their pdf document:
“SharePoint Server 2010 RTM Virtual Machine Setup Guide”.

These instructions will walk you through setting up Windows Server 2008R2, SQL Server 2008 R2, and SharePoint 2010 which is covers a good chunk of what we are installing.

Their instructions start with setting up a Hyper-V vhd which you can skip unless you are setting this up on a Microsoft Virtual Server system. You should be able to run a vhd created on a Virtual Server system on a Windows 7 64bit box using VirtualBox.

Since my intent is to create this VM on a Windows 7 64bit system here are my VirtualBox instructions.

Start VirtualBox and Click on New, click Next

image

  • Give your machine a name:   W2008R2CRMDEV
  • Operating System: Microsoft Windows
  • Version: Windows 2008 (64 bit)

image

Give it a minimum of 4Gb of memory or more if you can spare it.

image

Create a new hard Disk. Click Next and Next again at the Create Virtual Disk Wizard.

image

Select Dynamically expanding storage

image

The virtual disk is only 324Mb while empty and will only use as much disk space as it needs so give it 100Gb.Click the folder button to choose where you want to store this image.

image

Click Next and then click Finish.
Now you will want to make a few more adjustments.

image

Click on System then click on the Processor tab and add some CPU’s if you can so the installation will go faster. You can always reduce the memory or CPU’s later.

image

Click on Display and set the video memory to 128Mb.

image

Click on the Shared Folders and point to an area to access files. You will need this to install the SQL Server SP1 and Hotfix and for moving files around later.

image

Next Click Start

image

Click on the Folder and Browse to your ISO image of the Windows 2008R2 DVD
You can use a DVD, but it will be much slower.

image

Once you have your iso images added, you can run any of them for installations, by just selecting the .iso file and clicking the Select Button.

image

Once you have Windows 2008 installed make sure to install the Guest additions just so that the mouse transitions better.

Devices –> Install Guest Additions

When you need to reach the CRM executables access the shared drives in Windows Explorer       Network –> VBOXSVR –> \\VBOXSVR\Shared

image

Use the Critical Path instructions starting with the section to install Windows 2008R2 then SQL Server 2008R2 and SharePoint 2010.

Notes:

  1. When the Farm configuration Wizard is running, it could take an hour or longer and the IE screen can time out.  When the CPU finally calms down it is done. My VM was running about 100% on each CPU while this was running.
  2. The first time you bring up your default site it may time out a couple times and then finally work.

image

This gives you a great starting point to install the MS CRM 2011 Beta.

Important!!!! I would highly recommend that you make a copy of your VDI file at this point!  You may want to install various MS CRM 2011 release candidates and then the final RTM on this system later, or my might want to install MS CRM 4.0 on this system as well.  Also Visual Studio is great for a Development system, but you may want to create a DEMO system at some point without VS installed.

Friday, August 6, 2010

MS CRM 4.0 LINQ Support in CRM SDK 4.0.12

So far I really like what I have seen in this new SDK release MS CRM SDK.

It solves real problems and will actually make life better for CRM developers.

The new LINQ support can be used by people customizing their own propriety CRM systems and for integrators and xRM developers with software to deploy across different CRM schemas.

How they got it right and made life easier!

  1. The attributes can be directly accessed as simple types!
    • bool?  instead of  CrmBoolean
    • Guid   instead of   Key
    • etc..
  2. The related entities are associated as a list of entities like you would expect with LINQ
    • IEnumerable<contact>  instead of a BusinessEntityCollection.
    • Many less queries need to be coded greatly simplifying code.
      • Even though the additional queries are generated internally, they are done on the SQL side rather then requiring multiple web service calls which should be faster.
    • The related entity list names are predictable!
      • ex.  acct.account_contacts
      • ex.  acct.new_account_contact
    • Note: This is a significant improvement from the LINQtoSQL model that would just name related entities  contacts, contacts1, contacts2 without any way to predict which related list is which and wouldn’t give you a permanent way to set naming behavior. Adding an additional relationship to an entity that was already related could ruin your existing LINQ, requiring manual editing of the model xml.
  3. There is now much less of a reason to need to use the much more primitive Fetch type syntax.  string xmlResults = crmService.Fetch(xmlQuery);
  4. Entity classes do NOT need to be identical to the CRM schema for Selects!
  5. Entity classes do NOT need to be identical to the CRM schema for Updates!
    • According to MS the Update operation sends only modified attributes back to the server so you don’t have to care about anything else that’s been added.

In a nutshell

Strong typing and compile time errors
No web reference required
Easily regenerated Entity classes

Simple Maintenance

From a command line all you have to do is use the new crmsvcutil.exe to generate and update the LINQ Entity class source files. More information here.  MSDN reference

C:\> crmsvcutil /server:http://crm/Contoso /out:MyLinqEntities

One of the reasons I really appreciate this is that I wrote a utility to read all of the MS CRM Metadata and generate (Data Transfer Objects) or DTO’s for RIA services about a year ago along with all of the associated attributes for validation.  Idea for MS: If we had a switch on this utility to dynamically generate validation criteria attributes from the MS CRM metadata so that we could bind a control to it, that would be great for MVVM Silverlight apps!  Or generate them by default and just comment them out.

Getting Started:

David Yack has an explanation of how to set up MS CRM LINQ on your system and use it in a hello world project. There is no point duplicating his effort.

Sample Solution:

The following is a very simple sample solution 7.5Mb that is little more than the sample in the explanation link above. However the SDK libraries are included in the solution as are the Entity class files generated from the stock MS CRM 4.0 Contoso VM with a couple additions to the Account entity.

Since it ONLY accesses a couple standard fields in the Account entity it should work out of the box on any CRM 4 box once the Server name is set in the app.config file.  Just change the line below to whatever your local server name/orgname is and it should work.

Server=http://crm/Contoso;"/>

This is good stuff and the sooner you start using this the more time it will save you!

Saturday, October 3, 2009

MS CRM 4.0 Sending Attachments to the Browser

In a previous blog article I covered how to take files and make them attachments to emails. Creating Attachments to emails and annotations 

Recently I’ve been spending more time building portals to MS CRM, and have needed to make attached files available to the user by browser.

From a custom web app running with MS CRM you can always create a link like the following that will call the annotation editor screen which will let you download the attachment or delete it or add an additional attachment to the annotation.

string link = String.Format(@"{0}{1}/notes/edit.aspx?id={2}", crmServerBaseUrl, orgname, thisNote.annotationid.Value);

However sometimes when working with an external application you don’t have the ability to call the MS CRM functionality or for aesthetic reasons you want things to look differently. In this case I have a Silverlight 3 application with a completely different look and feel and I just need to retrieve annotation attachments from a list associated with an entity or contact. The ExportFile() method below would work just as well with an activitymimeattachment for email attachments.

The following aspx file simply takes an annotationid querystring, retrieves that annotation ( you provide the query) and sends the attached file to the user’s browser. The user will then be able to download the file or open the file in an appropriate application.

using System;
using System.Web;
using Passport.Web.Services.Logic;

namespace YourProject
{
    public partial class SendAnnotation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {           
            if (Request.QueryString["id"] != null)
            {                
                Guid annotationId = new Guid(Request.QueryString["id"].Replace("{", "").Replace("}", ""));

                // Get annotation
                annotation fileContainer = // fill in the query logic you need here.
                
                // Call method to write
                ExportFile(fileContainer.filename, fileContainer.documentbody, fileContainer.mimetype);             
            }
        }

        /// <summary>
        /// This method takes the annotation documentbody and writes it back to the browser
        /// with a file name and mimetype so that your browser knows how to intelligently 
        /// handle the file being sent to it.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="content"></param>
        /// <param name="type"></param>
        private void ExportFile(string fileName, string content, string type)
        {
            byte[] fileContent = Convert.FromBase64String(content);
            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            Response.ContentType = type;
            Response.BinaryWrite(fileContent);
            Response.End();
        }
        
    }

}

Thursday, July 30, 2009

MS CRM 4.0, xRM and building blocks

I have spent a number of years working with MS CRM as the end solution while integrating it with many other systems to make it the center of an organization’s business processes, data tracking and communication.

Change is good.

My emphasis has changed over the last year from business analysis, configuration, integration and customization of MS CRM to xRM systems that use MS CRM as a framework to build non-CRM solutions, and now leveraging MS CRM and xRM systems as a part of larger solutions.

My change in direction has also made me seriously think about what can be data driven and abstracted away to allow much more powerful solutions. I’m looking at MS CRM’s metadata in a completely new way these days as I integrate MS CRM with EF, RIA services and Silverlight 3. Taking a page from MS CRM’s form designer I’m now building Silverlight XAML based on metadata.

I’m also working on creating a developer level product out of my MS CRM import framework. (Think Scribe but for developers with complete control over everything for one time data migrations and for scheduled synchronizations.)

Enamored with MS

A real credit to the MS CRM framework is that I’m always looking at the holes in other technologies compared to what MS CRM allows as a development framework. It seems like they are all playing a game of catch up.

As a person who loves finding interesting ways to bend and mold MS CRM to do amazing things for businesses, I think the latest developments in EF, RIA and SL3 are really exciting. MS is really giving us great building blocks to create better and more powerful solutions that really improve the user experience. MS should be blushing right now and waiting for me to pucker up and give them a kiss.

Didn’t always feel this way

Now don’t get me wrong. I didn’t drink the MS Kool-Aid early in my career. I was focused around UNIX technologies for over a decade, QNX (digital Mastering console with proprietary parallel processing backplane), SCO UNIX (tracking nuclear waste shipments by satellite) and (Continuous Emissions Monitoring systems), Interactive, AIX ( Medical Systems ). I also touched HP/UX, IRIX, Coherent and Linux to a lesser extent. 

At one point all serious work was done in UNIX, period. Now that am creating business solutions, I really can’t see any competitors to the business infrastructure and products that MS has and is developing. MS has so many technologies that really deliver and connect together easily that I rarely feel like I can’t create a solution to any problem.  Maybe I’m just having some really good development days lately, but it just seems like a lot of new technologies are really evolving well.

So how does this impact my blog?

I’m still working with all of the MS CRM API’s, but have noticed that a lot of things are so second nature that I don’t even think about them any more. The result is that I have less urges to write a blog articles.  I continue to read and answer questions in the newsgroup microsoft.public.crm.developer which is sometimes a source of inspiration for blog articles, and I expect to add some content soon on using the MS CRM metadata web service, so time will tell.

I’m also considering creating a secondary blog dealing with the fun of global development, virtual dev teams, finding talent, maximizing personal productivity, tools and lessons learned.

Of course the trick is keeping balance in my life while doing this. I’ve been very fortunate that I continue to be found by some great customers who have been fun to work with and have very interesting and challenging work. I am even more fortunate to have a great wife who pulls me away from the computer to play ( cycling, mountain biking, hiking, etc.. ).

Looking forward to the road ahead!

Monday, June 22, 2009

RFC822 Import to MS CRM email activity utility

When migrating from Goldmine and some other CRM systems to MS CRM there is sometimes a need to import historical email.  This is frequently stored in a SQL database in rfc822 format. RFC822 is an email format standard.

What I am providing is a single class along with a file from the MS CRM SDK that this class currently uses. This single class is consolidated from a number of other classes in my import framework and is intended to give you a nearly complete rfc822 import solution that you can modify for your needs.  Every place that you need to make a modification according to your particular system has a //TODO: comment explaining what you need to adjust particular to your configuration. In addition assume that there will be some tweaking required, and make sure to do thorough debugging and testing to verify that your email records are being properly generated.

You can download the source code here.

There are 2 steps to using this class.

Part 1: Initialize a new RFC822ToEmailActivity object.

var emailConversion = new RFC822ToEmailActivity("Contoso"); // Your Orgname

Part 2: Calling the CreateEmailFromRfc822Record() method

CreateEmailFromRfc822Record() should be called in your loop that is reading the rfc822 records

var emailEntity = emailConversion.CreateEmailFromRfc822Record(     rfc822Record, // This is the string holding the whole 822 record     localEmailDomainName, // This is the local email domain name ex. onecrmpro.com      emailOwnerId, // systemUserId of email entity owner     relatedEntityName, // contact or account or....     relatedEntityId // id of the entity to regard the email to
)
  1. Calls parsing method
  2. Creates email attachments from pathnames returned from parsing method.
  3. Writes to an error log file with all attachments that are not found and other errors.
  4. Makes any other changes to the email entity before saving it.
  5. Sets Email State as completed (sent or received) based on local domain name.

Called Internally: ParseRFC822() parsing and email activity creation.

  1. Parse an rfc822 record
  2. Create an email activity based on that record.
  3. Compare email addresses, both To: and From: with a local domain name to decide if the email is incoming or outgoing.
  4. Create ActivityParties for To:, CC:, BCC:, From: related to CRM users, Contacts, Accounts and Leads in that match order precedence.
  5. Return a list of pathnames to any attachments.

RFC882 Email Attachments

Products like Gold Mine are storing email bodies in the database but they only have pathnames to the attachments. These attachment paths are frequently on the end user’s local computer which can be unreliable. These attachments may have been renamed, moved or deleted.

Hint1: Create a single shared folder on a file server with a separate tree branch for each computer that has attached files in the email history and modify the pathnames programmatically to match the structure you create on the file server.

Example:
S:\importattachments\C\Documents and Settings\mkovalcson\My Documents

Hint2: Comment out or create a test mode where nothing is written into the CRM database, but missing attachments are still written to a log file where you can see what isn’t found and decide how important it is to hunt attachments down before the final import.

You may want to look at this before you get started.
MS CRM Data Import (Cleaning up the Mess)

Saturday, June 13, 2009

MS CRM 4.0 Entity Mapping and Hidden Mappings

Microsoft has a powerful way to manage automatic attribute mappings from entities created from other entities. Typically we see this in the QOI process where an Opportunity is created, and then a Quote, Order or Invoice can be created from the Opportunity and much of the information is automatically copied from the Opportunity to that Quote, Order or Invoice.

Entity Mapping

If you open up your Opportunity from Customize Entities and look at 1:N Relationships, you can see the opportunity_quotes relationship.

image

If you double click on that you will see mappings. This shows you the names of each source opportunity attribute that is “Mapped” to a target quote attribute when a Quote is created from an opportunity.

image

This is very useful if you want to add custom fields and have those automatically propagated too or if you want to disable any default mappings.

So what about mapping the opportunityproduct? or quotedetail, salesorderdetail, and invoicedetail for that matter?

Hidden Entity Mapping

Step 1. You need the EntityMapId for the relationship that you want to map.

You can manually scan the EntityMapBase table matching against the SourceEntityName and TargetEntityName.

image

Or you can write a select like the one below to get a nice list of Guids to copy and paste into a temporary form.

Select TargetEntityName, EntityMapId from dbo.EntityMapBase
where SourceEntityName = 'opportunityproduct'

image

Step 2. Take the following URL and replace your server name and the EntityMapId of your choice to gain access to the rest of the mappingList editors.

http://localhost:5555/Tools/SystemCustomization/Relationships/Mappings/mappingList.aspx?mappingId=3A116CD4-A5EE-DD11-BDF0-0003FFEB167C

image

Saturday, May 23, 2009

CRM Demos, SSD Drives and Virtual Machines

When doing a demo you never want the software to look slow, and when doing CRM development against virtual machines performance is always critical to being efficient.

The Hardware
Samsung recently released their new 256Gb SSD drive and for me this drive signals that SSD drives have become mature. Intel has had very fast SSD drives available, but they were not very large. Like most other SSD drives they suffered from a condition where over time the drive would drop dramatically in performance. Samsung’s new drive has algorithms to minimize this to the point of it being of it being much less noticeable while still performing very similarly to the Intel SSD’s in access time and throughput.

So hoping that this drive lived up to my expectations, I replaced my laptop’s 7200 rpm 160Gb drive with Samsung’s new 256Gb SSD drive. My main concern was that running my VM’s off the system drive would still be unacceptable.

Virtual Machines
Before: I have run my vhd files from separate Firewire 800 Raid 0 drives. Keeping the system drive separate from the VHD was critical to getting good virtual machine performance.

After: The MS CRM 4.0 VHD 2009 now loads up in a mere 14 seconds while still running on the system drive versus 52 seconds on my external Firewire 800 drive. VS 2008 loads up after a clean boot(nothing cached) in 17 seconds and closes in 2 seconds compared with 57 and 13 seconds on my old drive.

Developing against a VM while on battery
This allows real development work to be done while running on battery power. The new SSD drive uses less power than the original drive did, and lugging around external drives for demos is now unnecessary.

As I write this the new Samsung drive is currently available at Dell as part 341-9999 for $699.99.  For this you get 256Gb at the speed of a 10,000 rpm RAID system that fits in a laptop while sipping at your batteries. In some ways, especially average access time, it actually blows an expensive and bulky RAID system away.

SSD-Drive_0785

Even MORE Speed Possible
I’ve seen reports twin drive laptops getting transfer rates of 300 MB/sec with two of these Samsung drives in a RAID 0 configuration. For comparison a single Samsung drive has a transfer rate of 200MB/sec which is still a lot faster than the 60Mb/sec of a 7200rpm internal laptop drive my less than a year old laptop was using.

The Installation
The replacement was easy. I used my Acronis backup software to make a complete disk backup to one of my external RAID drives. For my Dell M6300 I had to remove 4 screws, pull the drive out. Remove two more screws for the surrounding case. Screw the new drive into the case, slide it into the computer and put the 4 attaching screws back in. Boot from the Acronis CD. It recognizes all of my external drives USB and Firewire. Use the Acronis software to “add a drive” and partition it. Then restore the backup, remove the CD and reboot. The backup and restore(much faster) took me about 2.5 hours. Everything else took about 15 minutes.