Friday 27 April 2012

Embedding custom font or Dynamics CRM font in Silverlight 4.0

When you need to use a custom font/Dynamics CRM font which is not available in your Silverlight applications then just “embed” it as shown in this blog.

First of all get the font file (.ttf), if font is already exists at your system then you could find it at “C:\Windows\Font”; otherwise download that font file from the internet.

Here I’ve created simple Silverlight application having a label with Verdana fontfamily, as shown below.


Now, I want to change FontFamily for Label1 from “Verdana” to “Segoe UI” which is not available in Silverlight fonfamily.

Follow the below steps.

· Right click on Project.

· Select Add -> Existing Item.

· Select “segoeui.ttf” file.

· Click on Add.


Now, you could see “segoe.ttf” file in solution explorer.


Replace, FontFamily="Verdana" with FontFamily="segoeui.ttf#Segoe UI" in above code, Where “segoeui.ttf” is font file name that we recently imported in our application, “Segoe UI” is the name of the font available in that file and “#” works as delimiter. That’s it we are done.


Friday 20 April 2012

Programmatically change the customization for a system/custom entity in CRM 2011

Each and every entity of Dynamics CRM is having a “Formxml” that outlines the customization of the particular entity. In this blog I am going to explain you how to update the “Formxml” of any System/Custom entities.

To change customization we’ve to follow these steps.
· Retrieve formxml for that particular entity.
· Apply changes to that formxml.
· Publish updated formxml to CRM.

Here I’ve used custom entity “acm_airport” and applied changes on its formxml.
As shown in below screen shot there is a tab named as “Extra” having a section. I would like to add one more section with the same name (“Extra”) in this tab


Add following files in your class library project from this location “..\sdk\samplecode\cs\helpercode” once you have successfully downloaded Dynamics CRM SDK(5.0.7).
· crmservicehelpers.cs
· myorganizationcrmsdktypes.cs
· optionsets.cs

Use below code to get the fetchxml of acm_airport entity.
using System.Xml;
using System.Xml.XPath;
using Microsoft.Xrm.Sdk.Query;
string entityName = "acm_airport";
string tabName = "tab_Extra";
string sectionName = "section_Extra";
#region Retrieve Form XML
//Creates query expression to retrieve fromxml and form id for the specified object type code and form type='main'
QueryExpression myFormXml = new QueryExpression
EntityName = SystemForm.EntityLogicalName,
ColumnSet = new ColumnSet(new string[] { "formxml" }),
Criteria = new FilterExpression
Conditions = 
new ConditionExpression
//CRM represents EntityTypeName in ObjectTypeCode attribute
//Set 'Objecttypecode' as an Attribute name 
AttributeName = "objecttypecode",
Operator = ConditionOperator.Equal,
//set 'entityname' as value of an attribute
Values = { entityName }
new ConditionExpression
AttributeName = "type",
Operator = ConditionOperator.Equal,
Values = {"2"}
SystemForm systemForm = null;
EntityCollection entityCollection = organizationService.RetrieveMultiple(myFormXml);
In continuation with above code, use below code to update the retrieved formxml with new section named as “Extra” and publish the customization changes.

if (entityCollection.Entities.Count > 0)
#region Validate Specified Tab,Section and Insert Control
systemForm = (SystemForm)entityCollection[0];
//Loads form xml to customization
XmlDocument customization = new XmlDocument();
//Creates XPathNavigator
XPathNavigator xNav = customization.CreateNavigator();
//Set path to insert new section on mainform.
string validateTab = "//tabs/tab[@name='" + tabName + "']";
string validateSection = validateTab + "/columns/column/sections" +
"/section[@name='" + sectionName + "']";
//Creates new row to place new web resource control with necessary parameters
string newDDList = "<section name='" + sectionName + "' showlabel='false' showbar='false'                 locklevel='0' id='{6851ca85-b2a6-9689-ead3-3813de16082e}'                         IsUserDefined='0' layout='varwidth' columns='11' labelwidth='115'                     celllabelalignment='Left' celllabelposition='Left'> "+
"   <labels> "+
"    <label description='Extra' languagecode='1033' />"+
"   </labels> "+
"   <rows> "+
"     <row> "+
"     </row> "+
"   </rows> "+
XPathNodeIterator xIterTab = xNav.Select(xNav.Compile(validateTab));
//Validate specified Tab exists or not 
if (xIterTab.Count == 0)
throw new InvalidPluginExecutionException("Invalid Tab Name, Please verify");
XPathNodeIterator xIterSection = xNav.Select(xNav.Compile(validateSection));
//Validate specified Section exist or not 
if (xIterSection.Count > 0)
throw new InvalidPluginExecutionException("The Section is already configured on a                                     form. You cannot specify the existing "
+ "Section Name");
if (xNav.CanEdit)
XPathExpression xExpression = xNav.Compile(validateTab +                                             "/columns/column/sections/section");
//Select node using specified path in expression.
XPathNodeIterator xIter = xNav.Select(xExpression);
if (xIter.Count > 0)
//Moves navigator to next node from current set node
while (xIter.MoveNext())
//Checks position of current node is last node or not.
if (xIter.CurrentPosition == xIter.Count)
//if currnt node is last node then insert new element    
}                            }
#region Update Form xml
//Now we place the updated FormXml back into the systemform, and update                     it.
systemForm.FormXml = customization.InnerXml;
catch (Exception)
throw new InvalidPluginExecutionException("Failure: Updating the                     Formxml changes...");

After implementing the above code in a plug-in you can verify the updated formxml either opening a record or Airport entity or by validating the same via form customization. You could see the new section with “Extra” in the tab “Extra” as shown below.


Similarly, you can apply other required customization changes programmatically.

I hope this will be useful.

Friday 13 April 2012

Getting use of PublishXmlRequest SDK message to publish an Entity or a Web Resource

In Microsoft Dynamic CRM, when we perform any customization changes it is required to publish those changes. Below is the code which we can use to publish an Entity or a WebResource using “PublishXmlRequest” SDK message.

This code helps you to publish entity customization changes. Replace your entity’s logical name with below highlighted “entityName” variable.
#region Publish FormXMl
//Publish entity for which formxml has been changed 
PublishXmlRequest publishRequest = new PublishXmlRequest();
publishRequest.ParameterXml ="<importexportxml>" +
"    <entities>" +
"        <entity>" + entityName + "</entity>" +
"    </entities>" +
"    <nodes/>" +
"    <securityroles/>  " +
"    <settings/>" +
"    <workflows/>" +
catch (Exception)
throw new InvalidPluginExecutionException("Failure: FormXml                                                 publishing...");

Similarly, we can publish a web resource using below code. Here you have to use a GUID of web resource record. Replace your web resource GUID with below highlighted value.

#region Publish Web Resource
PublishXmlRequest publishRequest = new PublishXmlRequest ();
publishRequest.ParameterXml =
"<importexportxml>" +
"   <webresources>"+
"       <webresource>{" + webResource.Id +"}</webresource>"+
"   </webresources>" +
catch (Exception)
throw new InvalidPluginExecutionException("Failure: WebResource publishing...");

Below link will help you to identify what all other solution components can be published with PublishXmlRequest.

Wednesday 4 April 2012

Inkey solutions unveils another outstanding add-on for Dynamics CRM 2011 – GoalMetricEx


After getting a huge success for Drag and Drop Listbox, Inkey solutions unveils another outstanding add-on – GoalMetricEx.

This add-on enables you to calculate average of configured rollup fields on a Goal with Goal Metric of type Amount.

The calculated results will be displayed in a similar way on your existing Goal form.

Press the Recalculate button and GoalMetricEx will automatically generate the average values for a particular Goal.

For more details please refer below URL