I 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 = “
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(”
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);
}
Добрый день! < a href=”http://grantmaro.ru/mail/ luke@grantmaro.ru” >…< /a >
С уважением,
Frankie
June 15th, 2010
Добрый день! < a href=”http://tehnon.ru/mail/ jose@tehnon.ru” >…< /a >
с ув.
Kostya
June 19th, 2010