Hands On Coding

Franks Blog on Microsoft CRM, Sharepoint and .NET

About

Frank works as a Solution Architect, Microsoft Specialist and CEO of the German company hermes.tc, that is Microsoft ISV Empower Partner and specializes in business solutions.

ISV ReadinessI would like to put up for discussion how an ISV could organize an installer to setup and migrate your Microsoft CRM customizations to your clients’ server. First of all I make use of the Microsoft.Crm.Sdk.IsvReadiness Classes that ships as part of the ISVReadiness sample code from the CRM SDK. After I did my work on the custom entities and relations I export only the new entities (usually all entities that start with “new_”, if you didn’t change it) and save them to your visual studio installer project. Write the methods to import this XML-file programmatically and publish them:

private void importEntities()
{
  //Import custom entities
  ImportAllXmlRequest import = new ImportAllXmlRequest();
  using (StreamReader sr = new StreamReader("customentities.xml"))
  {
      string customizationXml = sr.ReadToEnd();
      import.CustomizationXml = customizationXml;
  }
  _crmservice.Execute(import);

  //Publish
  PublishAllXmlRequest publish = new PublishAllXmlRequest();
  _crmservice.Execute(publish);
}

Afterward change tht CRM system entities and set their relations to the custom entities (for example the lead entity):

private void changeLeadEntity()
{

  //Load the lead entity in an XmlDocument
  ExportXmlRequest export = new ExportXmlRequest();
  export.ParameterXml = “lead“;
  ExportXmlResponse entities = (ExportXmlResponse)_crmservice.Execute(export);
  XmlDocument xml = new XmlDocument();
  xml.PreserveWhitespace = true;
  xml.LoadXml(entities.ExportXml);

  //Add an attriute map to tell crm what to do with an atrribute if the user converts a lead to an opportunity
  XmlDocument map = new XmlDocument();
  map.LoadXml(”new_customsourceidnew_customtargetid“);

  XmlNode mapnode = map.DocumentElement;

  XmlElement attributemap = xml.CreateElement(”AttributeMap”);
  XmlElement attributesource = xml.CreateElement(”AttributeSource”);
  attributesource.InnerText = “new_customsourceid”;
  XmlElement attributetarget = xml.CreateElement(”AttributeTarget”);
  attributetarget.InnerText = “new_customtargetid”;

  attributemap.AppendChild(attributesource.Clone());
  attributemap.AppendChild(attributetarget.Clone());

  XmlNode newnode = xml.SelectSingleNode(”descendant::EntityTarget[@LocalizedName=’Opportunity’]”).ParentNode.SelectSingleNode(”AttributeMaps”).AppendChild(attributemap.Clone());

  //Add fields to the lead form
  FormCustomizer leadFormEditor = new FormCustomizer(xml, “connectpartners”);

  XmlDocument helper = new XmlDocument();
  helper = leadFormEditor.Xml;

  helper.SelectSingleNode(”descendant::tab[@id=’” + xml.SelectSingleNode(”descendant::tab”).Attributes[”id”].Value + “‘]/sections/section/labels/label[@description=’blabla’]”).ParentNode.ParentNode.ParentNode.RemoveChild(helper.SelectSingleNode(”descendant::tab[@id=’” + xml.SelectSingleNode(”descendant::tab”).Attributes[”id”].Value + “‘]/sections/section/labels/label[@description=’blabla’]”).ParentNode.ParentNode);
  leadFormEditor.Xml = helper;

  Guid sectionid = Guid.NewGuid();
  Guid tabid = new Guid(xml.SelectSingleNode(”descendant::tab”).Attributes[”id”].Value);

  //Add a lookup field to a new section
  leadFormEditor.AddSection(”lead”, tabid, sectionid, “testsection”, true, true, 0, “varwidth”, 11, 1031);
  leadFormEditor.AddCellToNewRow(”lead”, tabid, sectionid, “My Attribute”, “new_customattribute”, Microsoft.Crm.Sdk.IsvReadiness.SupportingItems.FormCustomizer.FieldDataType.Lookup, “”new_customattributeid”, false, true, false, 2, 1, 1031);

  //Add Javascript to the onload event
  if (!leadFormEditor.Xml.OuterXml.Contains(”newmethod”))
  {
  leadFormEditor.AddFormEventJScript(”lead”, “newmethod = function (){ doSomething(); windows.alert(’Done’);}”, Microsoft.Crm.Sdk.IsvReadiness.SupportingItems.FormCustomizer.JScriptType.onload, Microsoft.Crm.Sdk.IsvReadiness.SupportingItems.FormCustomizer.InsertionMode.InsertAfter, new string[] { });
  }

  //Import the modifications
  ImportAllXmlRequest import = new ImportAllXmlRequest();
  import.CustomizationXml = leadFormEditor.Xml.OuterXml;
  _crmservice.Execute(import);

  //Publish
  PublishAllXmlRequest publish = new PublishAllXmlRequest();
  _crmservice.Execute(publish);
}

Word 2007 with CRM LookupI found an interesting article on the Visual Studio Tools for Office SE and Microsoft CRM: Joris Kalz, Microsoft CRM specialist, shows a video on his blog that demonstrates the possibilites of an integration of Office 2007 and Microsoft CRM by utilizing the VSTO SE.
In this demo Microsoft Word 2007 has a Task Pane that enables the user to lookup data from the CRM (e.g. a proposals) , insert them into a word template and attach the generated file either as XPS or PDF file to a note of the regarding CRM entry. This looks very cool. The next consequent step towards integration of CRM and Office, would be to put the generated file in a sharepoint document library and link from the CRM entry to all regarding files.

Working With Microsoft Dynamics CRM 3.0Now and then I will recommend some books that deal with Microsoft CRM platform and my first pick is the definitive book for all those who start working with MS CRM, as it intruduces to the fundamentals of Microsoft CRM. It’s “Working With Microsoft Dynamics CRM 3.0″, written by Mike Snyder and Jim Steger. As both of them are members of a leading deployment consulting team, this is the only book written for both developers and those who implement business solutions. Take this book as a guideline for adapting Microsoft CRM to meet your or your customers exacting business needs. Mike and Jim deliver practical, hands-on information and provide case studies, integration and performance guidelines. Two thumbs up for the ultimate compendium for Microsoft CRM 3.0.

Microsoft CRM 4.0 (codename Titan)The forthcoming release of Microsoft CRM 4.0 (codename Titan) is said to be shipped in summer 2007 (summer in which part of the world, hu?) and I hardly can await it. As my company ITA Systemhaus participates in the Titan Ascend Program, I already had a little insight into the new features and I can say: Titan will be a titan. Microsoft CRM makes a big step ahead on its own path towards an omnipotent ERP platform. Many people and even developers think of it simply as a CRM and, yes, certainly you can manage your customer relations, but you can do much more than this and this it where Titan puts the emphasis.
The feature I yearned for years is the complete integration of the Windows Workflow Foundation into the CRM framework. So, you don’t have to click your proprietary workflows anymore, but design them in Visual Studio for example and you can reuse your workflow and activities in other project and other plattform (the workflow engine within Moss 2007 is the same!).
For the last couple of years, Microsoft has been moving toward providing a common ERP platform as part of its “Project Green”, which is devided into two phases: the 2005 to 2007 Green Wave 1 and 2008 to 2009+ Green Wave 2. Thus CRM 4.0 will just make the world ‘greener’ and at the end of the second wave, Microsoft will incoporate the best-of-breed features of the whole Dynamics family into one ERP product and believe me or not there will be a lot of Titan in it. I will introduce some more of these features in the next posts…