<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Zhongchen Zhou&#039;s Blog</title>
	<atom:link href="http://zhongchenzhou.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://zhongchenzhou.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sun, 19 May 2013 01:57:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='zhongchenzhou.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/4e9c80f142044beea158d0e5184ea5c7?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Zhongchen Zhou&#039;s Blog</title>
		<link>http://zhongchenzhou.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://zhongchenzhou.wordpress.com/osd.xml" title="Zhongchen Zhou&#039;s Blog" />
	<atom:link rel='hub' href='http://zhongchenzhou.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Dynamics Crm 2011 Trace Listener for Enterprise Library Logging</title>
		<link>http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-trace-listener-for-enterprise-library-logging/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-trace-listener-for-enterprise-library-logging/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 06:31:50 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=567</guid>
		<description><![CDATA[If you use Enterprise Library to log information and message in your program and you happen to develop Dynamics CRM related programs, then Dynamics Crm 2011 Trace Listener is a tool to log information and message to Dynamics CRM entity. If &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-trace-listener-for-enterprise-library-logging/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=567&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you use Enterprise Library to log information and message in your program and you happen to develop Dynamics CRM related programs, then Dynamics Crm 2011 Trace Listener is a tool to log information and message to Dynamics CRM entity. If you develop systems connected to Dynamics CRM then you can use this tool to have a central place to check the end results including the log.</p>
<p>It is available as NuGet package: <a title="http://nuget.org/packages/EnterpriseLibrary.Logging.DynamicsCrm2011" href="http://nuget.org/packages/EnterpriseLibrary.Logging.DynamicsCrm2011" target="_blank">http://nuget.org/packages/EnterpriseLibrary.Logging.DynamicsCrm2011</a></p>
<p>The project site is: <a title="http://entlibmscrmlog.codeplex.com/" href="http://entlibmscrmlog.codeplex.com/" target="_blank">http://entlibmscrmlog.codeplex.com/</a></p>
<p>After installing the NuGet package, there will be a folder added to visual studio project which includes two *.zip file. One is the un-managed Dynamics CRM solution and the other is managed Dynamics CRM solution. These two solutions are the sample except one being managed and the other is not. The solution contains one single entity where all the log information and message are saved.</p>
<p>After import the solution into Dynamics CRM organisation, you need to create a connection string in your web.config/app.config file.</p>
<p>The following is a sample configuration for On Premise Integrated Windows Authentication</p>
<pre class="brush: xml; title: ; notranslate">
&lt;pre&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
  &lt;connectionStrings&gt;
    &lt;add name=&quot;Crm&quot; connectionString=&quot;Url=https://domain.com/orgname;&quot;/&gt;
  &lt;/connectionStrings&gt;
&lt;/configuration&gt;&lt;/pre&gt;
</pre>
<p>More samples please see <a title="http://entlibmscrmlog.codeplex.com/" href="http://entlibmscrmlog.codeplex.com/" target="_blank">project site</a> or <a href="http://msdn.microsoft.com/en-us/library/gg695810.aspx">http://msdn.microsoft.com/en-us/library/gg695810.aspx</a></p>
<p>After than you can configure enterprise library logging using the configuration file either manually or using enterprise library configuration tool. It also support configuration through fluent API.</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=567&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-trace-listener-for-enterprise-library-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 14: Rhino Mocks with CRM plugin</title>
		<link>http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-unit-test-part-14-rhino-mocks-with-crm-plugin/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-unit-test-part-14-rhino-mocks-with-crm-plugin/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 06:04:49 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=563</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Rhino Mocks can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Rhino Mocks Unit test CRM plugin is straightforward as well, it is just &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-unit-test-part-14-rhino-mocks-with-crm-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=563&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Rhino Mocks can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Rhino Mocks" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-7e9dfef8" target="_blank">Dynamics CRM unit test using Rhino Mocks</a></p>
<p>Unit test CRM plugin is straightforward as well, it is just a bit tedious. IPlugin.Execute only accept one parameter which is IServiceProvider. Through IServiceProvider we can retrieve at least 3 interface and we need to set up 5 interface, which will be IOrganizationService, IPluginExecutionContext, ITracingService, IOrganizationServiceFactory and IServiceProvider.</p>
<p>Suppose we have a sample Dynamics CRM plugin, which is called after a contact is created within Dynamics CRM, if the parent customer is set to an account, the number of employees attribute of that account will be increased by one.</p>
<p><strong>Code Under Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public class Plugin : IPlugin
 {
 private string _unsecure, _secure;

/// &lt;summary&gt;
 /// Alias of the image registered for the snapshot of the
 /// primary entity's attributes after the core platform operation executes.
 /// The image contains the following attributes:
 /// parentcustomerid
 ///
 /// Note: Only synchronous post-event and asynchronous registered plug-ins
 /// have PostEntityImages populated.
 /// &lt;/summary&gt;
 private readonly string postImageAlias = &quot;PostCreateImage&quot;;

public Plugin(string unsecure, string secure)
 {
 _unsecure = unsecure;
 _secure = secure;
 }

public void Execute(IServiceProvider serviceProvider)
 {
 // Obtain the execution context service from the service provider.
 var pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (pluginExecutionContext.Stage == 40 &amp;&amp; pluginExecutionContext.MessageName == &quot;Create&quot; &amp;&amp; pluginExecutionContext.PrimaryEntityName == &quot;contact&quot;)
 {
 // Obtain the tracing service from the service provider.
 var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

// Obtain the Organization Service factory service from the service provider
 IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

// Use the factory to generate the Organization Service.
 var organizationService = factory.CreateOrganizationService(pluginExecutionContext.UserId);

Entity postImageEntity = (pluginExecutionContext.PostEntityImages != null &amp;&amp; pluginExecutionContext.PostEntityImages.Contains(this.postImageAlias)) ? pluginExecutionContext.PostEntityImages[this.postImageAlias] : null;

// when a contact is created with parent account, increase number of employees for that account
 if (postImageEntity != null &amp;&amp; postImageEntity.Contains(&quot;parentcustomerid&quot;))
 {
 EntityReference parentCustomer = postImageEntity.GetAttributeValue&lt;EntityReference&gt;(&quot;parentcustomerid&quot;);

if (parentCustomer != null &amp;&amp; parentCustomer.LogicalName.ToLowerInvariant() == &quot;account&quot;)
 {
 tracingService.Trace(&quot;Parent account id: {0}.&quot;, parentCustomer.Id);

Entity parentAccount = organizationService.Retrieve(&quot;account&quot;, parentCustomer.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(&quot;numberofemployees&quot;));

int numberOfEmployees = 0;
 if (parentAccount.Contains(&quot;numberofemployees&quot;))
 {
 numberOfEmployees = parentAccount.GetAttributeValue&lt;int&gt;(&quot;numberofemployees&quot;);
 }

parentAccount[&quot;numberofemployees&quot;] = numberOfEmployees + 1;

organizationService.Update(parentAccount);
 }
 }
 }
 }
 }

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">
[TestMethod()]
 public void ExecuteTest()
 {
 //
 // Arrange
 //
 string unsecure = &quot;unsecure&quot;;
 string secure = &quot;secure&quot;;
 Plugin target = new Plugin(unsecure, secure);

var accountId = Guid.NewGuid();
 var previousNumber = 3;
 var expected = 4;
 var actual = 0;

// IOrganizationService
 var service = MockRepository.GenerateStub&lt;IOrganizationService&gt;();
 service.Stub(x =&gt; x.Retrieve(null, Guid.Empty, null)).IgnoreArguments().Return(
 new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;)
 {
 Id = accountId,
 Attributes = { { &quot;numberofemployees&quot;, previousNumber } }
 });

service.Stub(x =&gt; x.Update(null)).IgnoreArguments().Do((Action&lt;Entity&gt;)delegate(Entity entity)
 {
 actual = entity.GetAttributeValue&lt;int&gt;(&quot;numberofemployees&quot;);
 });

// IPluginExecutionContext
 var pluginExecutionContext = MockRepository.GenerateStub&lt;IPluginExecutionContext&gt;();
 pluginExecutionContext.Stub(x =&gt; x.Stage).Return(40);
 pluginExecutionContext.Stub(x =&gt; x.MessageName).Return(&quot;Create&quot;);
 pluginExecutionContext.Stub(x =&gt; x.PrimaryEntityName).Return(&quot;contact&quot;);
 pluginExecutionContext.Stub(x =&gt; x.PostEntityImages).Return(new EntityImageCollection
 {
 { &quot;PostCreateImage&quot;, new Microsoft.Xrm.Sdk.Entity(&quot;contact&quot;)
 {
 Attributes = { { &quot;parentcustomerid&quot;, new EntityReference(&quot;account&quot;, accountId) } }
 }
 }
 });

// ITracingService
 var tracingService = MockRepository.GenerateStub&lt;ITracingService&gt;();
 tracingService.Stub(x =&gt; x.Trace(null, null)).IgnoreArguments().Do((Action&lt;string, object[]&gt;)delegate(string f, object[] o)
 {
 Debug.WriteLine(f, o);
 });

// IOrganizationServiceFactory
 var factory = MockRepository.GenerateStub&lt;IOrganizationServiceFactory&gt;();
 factory.Stub(x =&gt; x.CreateOrganizationService(null)).IgnoreArguments().Return(service);

// IServiceProvider
 var serviceProvider = MockRepository.GenerateStub&lt;IServiceProvider&gt;();
 serviceProvider.Stub(x =&gt; x.GetService(null)).IgnoreArguments().Do((Func&lt;Type, object&gt;)delegate(Type t)
 {
 if (t == typeof(IPluginExecutionContext))
 {
 return pluginExecutionContext;
 }
 else if (t == typeof(ITracingService))
 {
 return tracingService;
 }
 else if (t == typeof(IOrganizationServiceFactory))
 {
 return factory;
 }

return null;
 });

//
 // Act
 //
 target.Execute(serviceProvider);

//
 // Assert
 //
 Assert.AreEqual(expected, actual);
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=563&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-unit-test-part-14-rhino-mocks-with-crm-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 11: QUnit with client side JavaScript</title>
		<link>http://zhongchenzhou.wordpress.com/2012/10/31/dynamics-crm-2011-unit-test-part-11-qunit-with-client-side-javascript/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/10/31/dynamics-crm-2011-unit-test-part-11-qunit-with-client-side-javascript/#comments</comments>
		<pubDate>Wed, 31 Oct 2012 10:32:49 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=557</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using QUnit can be downloaded from MSDN sample gallery: http://code.msdn.microsoft.com/Dynamics-CRM-2011-client-9f189663 This post describe how to use QUnit and Xrm.Page Script Library Template (Microsoft Visual Studio extension) to &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/10/31/dynamics-crm-2011-unit-test-part-11-qunit-with-client-side-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=557&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using QUnit can be downloaded from MSDN sample gallery: <a href="http://code.msdn.microsoft.com/Dynamics-CRM-2011-client-9f189663">http://code.msdn.microsoft.com/Dynamics-CRM-2011-client-9f189663</a></p>
<p>This post describe how to use QUnit and Xrm.Page Script Library Template (Microsoft Visual Studio extension) to unit test Dynamics CRM 2011 client side jQuery or JavaScript code.</p>
<p>More information on Xrm.Page Script Library Templatecan be found: <a href="http://msdn.microsoft.com/en-us/library/gg328261.aspx#BKMK_DevelopmentTools">http://msdn.microsoft.com/en-us/library/gg328261.aspx#BKMK_DevelopmentTools</a></p>
<p>More information on QUnit can be found: <a href="http://qunitjs.com/">http://qunitjs.com/</a></p>
<p>Suppose we have one JavaScript web resource which will run when account form load. The client side JavaScript code will update the &#8220;Account Name&#8221; label to &#8220;Organisation Name&#8221; and set Preferred User look up field value to the Preferred User of the Primary Contact of the current account.</p>
<p><strong>Code Under Test</strong></p>
<pre class="brush: jscript; title: ; notranslate">

/// &lt;reference path=&quot;XrmPageTemplate.js&quot; /&gt;

//This Library uses a namespace naming strategy to help prevent duplication function names
if (typeof (Zzhou) == &quot;undefined&quot;)
{ Zzhou = { __namespace: true }; }
if (typeof (Zzhou.Qunit) == &quot;undefined&quot;)
{ Zzhou.Qunit = { __namespace: true }; }
// Namespace container for functions in this library.
Zzhou.Qunit.Account = {
 onload: function () {
 var attrName = 'name',
 label = 'Organisation Name';
 this._changeControlLabel(attrName, label);
 this._updatePreferredUser();
 },
 _changeControlLabel: function (attrName, label) {
 var control = Xrm.Page.getControl(attrName);
 if (control) {
 control.setLabel(label);
 }
 },
 _updatePreferredUser: function () {
 // primary contact look up field name
 var attrName = 'primarycontactid';
 // get primary contact attribute
 var attribute = Xrm.Page.getAttribute(attrName);
 if (attribute) {
 // get primary contact attribute value
 var attrValue = attribute.getValue();
 if (attrValue &amp;&amp; attrValue[0] &amp;&amp; attrValue[0].entityType === 'contact') {
 // get primary contact id
 var primaryContactId = attrValue[0].id;
 // retrieve primary contact.PreferredSystemUserId
 SDK.JQuery.retrieveRecord(
 primaryContactId,
 &quot;Contact&quot;,
 &quot;PreferredSystemUserId&quot;,
 null,
 // success call back
 function (user) {
 if (user &amp;&amp; user.PreferredSystemUserId) {
 var attrName = 'preferredsystemuserid';
 var attribute = Xrm.Page.getAttribute(attrName);
 if (attribute) {
 var lookupReference = [];
 lookupReference[0] = {};
 lookupReference[0].id = user.PreferredSystemUserId.Id;
 lookupReference[0].entityType = user.PreferredSystemUserId.LogicalName;
 lookupReference[0].name = user.PreferredSystemUserId.Name;

attribute.setValue(lookupReference);
 }
 }
 },
 function (error) {
 alert(error.message);
 }
 );
 }
 }
 },
 __namespace: true
};

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: jscript; title: ; notranslate">

/// &lt;reference path=&quot;XrmPageTemplate.js&quot; /&gt;
module(
 'Account Form Library Test',
 {
 setup: function () {
 this.savedAjax = $.ajax;
 },
 teardown: function () {
 $.ajax = this.savedAjax;
 }
 }
 );
test(&quot;Zzhou.Qunit.Account._changeControlLabel&quot;, function () {
 //
 // Arrange
 //
 var attrName = 'name',
 expectedLabel = 'Organisation Name';
 //
 // Act
 //
 Zzhou.Qunit.Account._changeControlLabel(attrName, expectedLabel);

//
 // Assert
 //
 var actualLabel, control = Xrm.Page.getControl(attrName);
 if (control) {
 actualLabel = control.getLabel();
 }
 strictEqual(actualLabel, expectedLabel, &quot;actualLabel and expectedLabel are the same value and type&quot;);
});
test(&quot;Zzhou.Qunit.Account._updatePreferredUser&quot;, function () {
 expect(3);

//
 // Arrange
 //
 var data = {
 d: {
 PreferredSystemUserId: {
 Id: '5bcf7e47-9993-e111-88fa-00155d4c5b01',
 LogicalName: 'systemuser',
 Name: 'First name Last name'
 }
 }
 };
 $.ajax = function (options) {
 options.success(data, &quot;success&quot;, { responseText: JSON.stringify(data) });
 };

//
 // Act
 //
 Zzhou.Qunit.Account._updatePreferredUser();

//
 // Assert
 //
 var attrName = 'preferredsystemuserid';
 var attribute = Xrm.Page.getAttribute(attrName);
 if (attribute) {
 var attrValue = attribute.getValue();
 if (attrValue &amp;&amp; attrValue[0]) {
 strictEqual(attrValue[0].entityType, data.d.PreferredSystemUserId.LogicalName);
 strictEqual(attrValue[0].id, data.d.PreferredSystemUserId.Id);
 strictEqual(attrValue[0].name, data.d.PreferredSystemUserId.Name);
 }
 }
});

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=557&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/10/31/dynamics-crm-2011-unit-test-part-11-qunit-with-client-side-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Rollup Update 11 IFD not working Failed to get priv user group information</title>
		<link>http://zhongchenzhou.wordpress.com/2012/10/30/dynamics-crm-2011-rollup-update-11-ifd-not-working-failed-to-get-priv-user-group-information/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/10/30/dynamics-crm-2011-rollup-update-11-ifd-not-working-failed-to-get-priv-user-group-information/#comments</comments>
		<pubDate>Tue, 30 Oct 2012 10:38:10 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=555</guid>
		<description><![CDATA[Update: &#160; A fix can be found from the following link http://community.dynamics.com/product/crm/f/117/t/93178.aspx Microsoft just provided me with a work around while they work on the hot fix. • Change the Anonymous user identity of IIS Anonymous Authentication Credentials to Application &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/10/30/dynamics-crm-2011-rollup-update-11-ifd-not-working-failed-to-get-priv-user-group-information/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=555&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Update:</p>
<p>&nbsp;</p>
<p>A fix can be found from the following link</p>
<p><a href="http://community.dynamics.com/product/crm/f/117/t/93178.aspx" rel="nofollow">http://community.dynamics.com/product/crm/f/117/t/93178.aspx</a></p>
<p>Microsoft just provided me with a work around while they work on the hot fix.</p>
<p>• Change the Anonymous user identity of IIS Anonymous Authentication Credentials to Application pool Identity option:</p>
<p>1. On the CRM server, open the Internet Information Services (IIS) Manager;</p>
<p>2. In IIS Manager, click the CRM site;</p>
<p>3. In the Features View, double-click Authentication;</p>
<p>4. Select Anonymous Authentication , and then click Edit in the Actions pane;</p>
<p>5. In the Edit Anonymous Authentication Credentials dialog box, click the Application pool Identity , and then click Ok;</p>
<p>6. Do an IISRESET on CRM and ADFS server.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>I have on premise IFD deployment, after install Rollup Update 11, it is not working, i keep get the following errors</p>
<pre class="brush: plain; title: ; notranslate">

Microsoft CRM Error Report:
Error Description:
Failed to get priv user group information. k = 1b813725-c917-4291-bcea-277fca8e799e privUserGroupId: 5140579c-a508-40a3-943b-fed25dac4842, localSystemAdGuid: 00000000-0000-0000-0000-000000000000, Exception: Microsoft.Crm.CrmSecurityException: Could not find GUID for server: VMCRM$ With SearchFilter:samAccountName at Microsoft.Crm.SecurityUtils.GetGuid(String searchItem, String searchFilter, String searchItemLogInfo, Boolean exceptionIfNotfound) at Microsoft.Crm.SecurityUtils.GetLocalSystemGuid() at Microsoft.Crm.Caching.OrganizationSettingsCacheLoader.LoadCacheData(Guid key, ExecutionContext context).

Error Details:
Failed to get priv user group information. k = 1b813725-c917-4291-bcea-277fca8e799e privUserGroupId: 5140579c-a508-40a3-943b-fed25dac4842, localSystemAdGuid: 00000000-0000-0000-0000-000000000000, Exception: Microsoft.Crm.CrmSecurityException: Could not find GUID for server: VMCRM$ With SearchFilter:samAccountName
 at Microsoft.Crm.SecurityUtils.GetGuid(String searchItem, String searchFilter, String searchItemLogInfo, Boolean exceptionIfNotfound)
 at Microsoft.Crm.SecurityUtils.GetLocalSystemGuid()
 at Microsoft.Crm.Caching.OrganizationSettingsCacheLoader.LoadCacheData(Guid key, ExecutionContext context).

Full Stack:
[CrmSecurityException: Could not find GUID for server: VMCRM$ With SearchFilter:samAccountName]
 at Microsoft.Crm.SecurityUtils.GetGuid(String searchItem, String searchFilter, String searchItemLogInfo, Boolean exceptionIfNotfound)
 at Microsoft.Crm.SecurityUtils.GetLocalSystemGuid()
 at Microsoft.Crm.Caching.OrganizationSettingsCacheLoader.LoadCacheData(Guid key, ExecutionContext context)

[CrmException: Failed to get priv user group information. k = 1b813725-c917-4291-bcea-277fca8e799e privUserGroupId: 5140579c-a508-40a3-943b-fed25dac4842, localSystemAdGuid: 00000000-0000-0000-0000-000000000000, Exception: Microsoft.Crm.CrmSecurityException: Could not find GUID for server: VMCRM$ With SearchFilter:samAccountName
 at Microsoft.Crm.SecurityUtils.GetGuid(String searchItem, String searchFilter, String searchItemLogInfo, Boolean exceptionIfNotfound)
 at Microsoft.Crm.SecurityUtils.GetLocalSystemGuid()
 at Microsoft.Crm.Caching.OrganizationSettingsCacheLoader.LoadCacheData(Guid key, ExecutionContext context).]
 at Microsoft.Crm.Caching.OrganizationSettingsCacheLoader.LoadCacheData(Guid key, ExecutionContext context)
 at Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext context)
 at Microsoft.Crm.Caching.CrmMultiOrgCache`2.CreateEntry(TKey key, IOrganizationContext context)
 at Microsoft.Crm.Caching.CrmMultiOrgCache`2.LookupEntry(TKey key, IOrganizationContext context)
 at Microsoft.Crm.Authentication.Claims.ClaimsUtility.GetAuthenticationMethod(Guid organizationId, String method)
 at Microsoft.Crm.Authentication.Claims.CrmFederatedAuthenticationModule.SendToIdentityProvider(RedirectLocation redirectLocation)
 at Microsoft.Crm.Authentication.Claims.CrmFederatedAuthenticationModule.OnEndRequestHandler(Object sender, EventArgs e)
 at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
 at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
Other Message:

Error Number:
0x80040216

Source File:
Not available

Line Number:
Not available

Error Trace:

&amp;nbsp;

Date: 10-30-2012

Time: 20:09:56

Server: default.zhongchenzhou.com
Request URL:

https://default.zhongchenzhou.com/default.aspx

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=555&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/10/30/dynamics-crm-2011-rollup-update-11-ifd-not-working-failed-to-get-priv-user-group-information/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 IE10 cannot import solution script error</title>
		<link>http://zhongchenzhou.wordpress.com/2012/10/29/dynamics-crm-2011-ie10-cannot-import-solution-script-error/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/10/29/dynamics-crm-2011-ie10-cannot-import-solution-script-error/#comments</comments>
		<pubDate>Mon, 29 Oct 2012 09:39:59 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=550</guid>
		<description><![CDATA[When use IE10 together with Dynamics CRM 2011 (Rollup Update 10) and try to import a solution, there is a error window popup This is caused by a script error in file After change the code to Another error comes &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/10/29/dynamics-crm-2011-ie10-cannot-import-solution-script-error/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=550&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When use IE10 together with Dynamics CRM 2011 (Rollup Update 10) and try to import a solution, there is a error window popup</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror.png"><img class="alignnone size-medium wp-image-551" title="ie10importsolutionerror" alt="" src="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror.png?w=300&#038;h=189" height="189" width="300" /></a></p>
<p>This is caused by a script error in file</p>
<pre class="brush: plain; title: ; notranslate">~\Tools\Solution\import\SolutionImportProcess.aspx</pre>
<pre class="brush: jscript; title: ; notranslate">function window.onload() {</pre>
<p>After change the code to</p>
<pre class="brush: jscript; title: ; notranslate">window.onload = function () {</pre>
<p>Another error comes</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror2.png"><img class="alignnone size-medium wp-image-552" title="ie10importsolutionerror2" alt="" src="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror2.png?w=300&#038;h=240" height="240" width="300" /></a></p>
<p>&nbsp;</p>
<p>If click on cancel, another error comes</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror3.png"><img class="alignnone size-medium wp-image-553" title="ie10importsolutionerror3" alt="" src="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror3.png?w=300&#038;h=240" height="240" width="300" /></a></p>
<p>&nbsp;</p>
<p>Anyone know how to fix this?</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=550&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/10/29/dynamics-crm-2011-ie10-cannot-import-solution-script-error/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror.png?w=300" medium="image">
			<media:title type="html">ie10importsolutionerror</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror2.png?w=300" medium="image">
			<media:title type="html">ie10importsolutionerror2</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/10/ie10importsolutionerror3.png?w=300" medium="image">
			<media:title type="html">ie10importsolutionerror3</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint Sample 1</title>
		<link>http://zhongchenzhou.wordpress.com/2012/09/23/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint-sample-1/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/09/23/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint-sample-1/#comments</comments>
		<pubDate>Sat, 22 Sep 2012 14:40:46 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Kendo UI]]></category>
		<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=539</guid>
		<description><![CDATA[The complete source code can be download from sample gallery: Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint Kendo UI is a HTML5, jQuery-based framework for building modern HTML apps. Kendo UI combines the best of emerging HTML5, &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/09/23/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint-sample-1/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=539&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The complete source code can be download from sample gallery: <a title="Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint" href="http://code.msdn.microsoft.com/Kendo-UI-DataSource-Kendo-33a3dc77" target="_blank">Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint</a></p>
<p><a title="Kendo UI" href="http://www.kendoui.com/" target="_blank">Kendo UI</a> is a HTML5, jQuery-based framework for building modern HTML apps. Kendo UI combines the best of emerging HTML5, CSS3, and JavaScript technologies with robust, cross-browser techniques to deliver a framework that is both powerfully rich and broadly compatible with older browsers.</p>
<p><a title="MS Dynamic CRM R8 CTP Beta" href="https://connect.microsoft.com/site68\/Downloads" target="_blank">Microsoft Dynamics CRM 2011 Release 8</a> include support for IE, Chrome, Firefox and Safari.</p>
<p>By using a powerful JavaScript framework, the use of ASP.NET is reduced which would remove the complexity of deployment which also makes the solution much more portable.</p>
<p>By using Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint, it is easy to implement server side filter, sorting and paging.</p>
<p>There are a few tricks to use Kendo UI together with Dynamics CRM 2011 I want to share. The complete code is in the end of this post.</p>
<p>1. Microsoft Dynamics CRM 2011 REST Endpoint does <strong>not</strong> support <strong>$format</strong> system query option.</p>
<p>You can use a global jQuery ajax event handler to specifying http header ensures that the results will be returned as JSON.</p>
<pre class="brush: jscript; title: ; notranslate">

$(document).ajaxSend(function (e, jqxhr, settings) {
 if (settings.url.toLowerCase().indexOf(&quot;XRMServices/2011/OrganizationData.svc&quot;.toLowerCase()) &gt;= 0) {
 jqxhr.setRequestHeader(&quot;Accept&quot;, &quot;application/json&quot;);
 }
});

</pre>
<p>2. Microsoft Dynamics CRM 2011 REST Endpoint does <strong>not</strong> support <strong>$inlinecount, $count</strong> system query option.</p>
<p>you can set a function to use fetch xml and soap endpoint to return the total record count.</p>
<pre class="brush: jscript; title: ; notranslate">

var dataSource = new kendo.data.DataSource({
 schema: {
 total: function (data) {
var fetchXml = '&lt;fetch mapping=&quot;logical&quot; aggregate=&quot;true&quot;&gt;' +
 '&lt;entity name=&quot;account&quot;&gt;' +
 &quot;&lt;attribute name='accountid' alias='count' aggregate='count'/&gt;&quot; +
 '&lt;/entity&gt;' +
 '&lt;/fetch&gt;';

var context = GetGlobalContext();

var serverUrl = window.parent.document.location.protocol + '//' + window.parent.document.location.host + '/' + context.getOrgUniqueName();

var _oService = new FetchUtil(context.getOrgUniqueName(), serverUrl);
 var res = _oService.Fetch(fetchXml);

var count = res[0].attributes.count.formattedValue;

return count;
 }
 }
});

</pre>
<p>3. you need to stop Kendo UI to send default query string parameter and use Dynamics CRM 2011 specific format</p>
<pre class="brush: jscript; title: ; notranslate">

var dataSource = new kendo.data.DataSource({
 transport: {
 parameterMap: function (options) {
 return {
 $top: options.take,
 $skip: options.skip,
 $select: 'Name,Telephone1,Address1_City'',
 $orderby: options.sort[0].field + ' ' + options.sort[0].dir
 };
 }
 }
});

</pre>
<p>4. you have to parse returned json object to return object array that Kendo UI understand</p>
<pre class="brush: jscript; title: ; notranslate">

var dataSource = new kendo.data.DataSource({
 schema: {
 parse: function (data) {
 return data.d.results;
 },
 type: &quot;json&quot;
 }
});

</pre>
<p><strong>Complete Kendo UI DataSource code</strong></p>
<pre class="brush: jscript; title: ; notranslate">
var context = GetGlobalContext();

var serverUrl = window.parent.document.location.protocol + '//' + window.parent.document.location.host + '/' + context.getOrgUniqueName();

dataSource = new kendo.data.DataSource({
 transport: {
 read: {
 url: serverUrl + &quot;/XRMServices/2011/OrganizationData.svc/AccountSet&quot;,
 dataType: 'json'
 },
 parameterMap: function (options) {
 var parameter = {
 $top: options.take,
 $skip: options.skip,
 $select: 'Name,Telephone1,Address1_City',
 $orderby: options.sort[0].field + ' ' + options.sort[0].dir
 };

return parameter;
 }
 },
 schema: {
 model: {
 id: &quot;AccountId&quot;,
 fields: {
 Name: { type: &quot;string&quot; },
 Telephone1: { type: &quot;string&quot; },
 Address1_City: { type: &quot;string&quot; }
 }
 },
 total: function (data) {

var fetchXml = '&lt;fetch mapping=&quot;logical&quot; aggregate=&quot;true&quot;&gt;' +
 '&lt;entity name=&quot;account&quot;&gt;' +
 &quot;&lt;attribute name='accountid' alias='count' aggregate='count'/&gt;&quot; +
 '&lt;/entity&gt;' +
 '&lt;/fetch&gt;';

var _oService = new FetchUtil(context.getOrgUniqueName(), serverUrl);
 var res = _oService.Fetch(fetchXml);

var count = res[0].attributes.count.formattedValue;

return count;
 },
 parse: function (data) {
 return data.d.results;
 },
 type: &quot;json&quot;
 },
 serverPaging: true,
 pageSize: 10,
 serverSorting: true,
 sort: { field: &quot;Name&quot;, dir: &quot;asc&quot; }
 });
</pre>
<p><strong>Complete Sample code</strong></p>
<pre class="brush: jscript; title: ; notranslate">
&lt;!DOCTYPE html&gt;

&lt;html lang=&quot;en&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
 &lt;meta charset=&quot;utf-8&quot; /&gt;
 &lt;title&gt;Kendo UI Demo&lt;/title&gt;
 &lt;!-- CDN-based stylesheet references for Kendo UI Web --&gt;
 &lt;link rel=&quot;stylesheet&quot; href=&quot;http://cdn.kendostatic.com/2012.2.913/styles/kendo.common.min.css&quot; /&gt;
 &lt;link rel=&quot;stylesheet&quot; href=&quot;http://cdn.kendostatic.com/2012.2.913/styles/kendo.default.min.css&quot; /&gt;
&lt;/head&gt;
&lt;body style=&quot;border-width: 0px; padding-left: 0px; padding-top: 0px; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px&quot;&gt;
 &lt;div id=&quot;grid&quot;&gt;&lt;/div&gt;
 &lt;!-- CDN-based script reference for jQuery --&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js&quot;&gt;&lt;/script&gt;
 &lt;!-- CDN-based script reference for Kendo UI DataViz --&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;http://cdn.kendostatic.com/2012.2.913/js/kendo.web.min.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;ClientGlobalContext.js.aspx&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
 $(document).ready(function ($) {

var context = GetGlobalContext();

var serverUrl = window.parent.document.location.protocol + '//' + window.parent.document.location.host + '/' + context.getOrgUniqueName();

dataSource = new kendo.data.DataSource({
 transport: {
 read: {
 url: serverUrl + &quot;/XRMServices/2011/OrganizationData.svc/AccountSet&quot;,
 dataType: 'json'
 },
 parameterMap: function (options) {
 var parameter = {
 $top: options.take,
 $skip: options.skip,
 $select: 'Name,Telephone1,Address1_City',
 $orderby: options.sort[0].field + ' ' + options.sort[0].dir
 };

return parameter;
 }
 },
 schema: {
 model: {
 id: &quot;AccountId&quot;,
 fields: {
 Name: { type: &quot;string&quot; },
 Telephone1: { type: &quot;string&quot; },
 Address1_City: { type: &quot;string&quot; }
 }
 },
 total: function (data) {

var fetchXml = '&lt;fetch mapping=&quot;logical&quot; aggregate=&quot;true&quot;&gt;' +
 '&lt;entity name=&quot;account&quot;&gt;' +
 &quot;&lt;attribute name='accountid' alias='count' aggregate='count'/&gt;&quot; +
 '&lt;/entity&gt;' +
 '&lt;/fetch&gt;';

var _oService = new FetchUtil(context.getOrgUniqueName(), serverUrl);
 var res = _oService.Fetch(fetchXml);

var count = res[0].attributes.count.formattedValue;

return count;
 },
 parse: function (data) {
 return data.d.results;
 },
 type: &quot;json&quot;
 },
 serverPaging: true,
 pageSize: 10,
 serverSorting: true,
 sort: { field: &quot;Name&quot;, dir: &quot;asc&quot; }
 });

var grid = $(&quot;#grid&quot;).kendoGrid({
 dataSource: dataSource,
 height: 450,
 columns: [{
 template: '&lt;input type=&quot;checkbox&quot; /&gt;',
 sortable: false,
 width: 45
 },
 {
 title: 'Account Name',
 field: &quot;Name&quot;,
 width: 180
 },
 {
 title: 'Main Phone',
 field: &quot;Telephone1&quot;,
 width: 300
 },
 {
 title: 'Address 1: City',
 field: &quot;Address1_City&quot;,
 filterable: false,
 width: 300,
 sortable: false
 }],
 editable: false,
 pageable: true,
 selectable: &quot;multiple, row&quot;,
 sortable: {
 mode: 'single',
 allowUnsort: false
 },
 dataBound: function () {
 grid.table.find(&quot;tr&quot;).find(&quot;td:first input&quot;)
 .change(function (e) {
 if (!$(this).prop('checked')) {
 grid.clearSelection();
 }
 });
 },
 change: function (e) {
 window.setTimeout(function () {
 var checkbox = $(e.sender.select()[0]).find(&quot;td:first input&quot;).prop(&quot;checked&quot;, true);
 grid.table.find(&quot;tr&quot;).find(&quot;td:first input:checked&quot;).not(checkbox).prop(&quot;checked&quot;, false);
 }, 0);
 }
 }).data(&quot;kendoGrid&quot;);

grid.thead.find(&quot;th:first&quot;)
 .append($('&lt;input class=&quot;selectAll&quot; type=&quot;checkbox&quot;/&gt;'))
 .delegate(&quot;.selectAll&quot;, &quot;click&quot;, function () {
 var checkbox = $(this);

grid.table.find(&quot;tr&quot;)
 .find(&quot;td:first input&quot;)
 .attr(&quot;checked&quot;, checkbox.is(&quot;:checked&quot;))
 .trigger(&quot;change&quot;);
 });
 }).ajaxSend(function (e, jqxhr, settings) {
 if (settings.url.toLowerCase().indexOf(&quot;XRMServices/2011/OrganizationData.svc&quot;.toLowerCase()) &gt;= 0) {
 jqxhr.setRequestHeader(&quot;Accept&quot;, &quot;application/json&quot;);
 }
 });
 &lt;/script&gt;
 &lt;script id=&quot;FetchUtil&quot; type=&quot;text/javascript&quot;&gt;
 var XMLHTTPSUCCESS = 200;
 var XMLHTTPREADY = 4;

function FetchUtil(sOrg, sServer) {
 this.org = sOrg;
 this.server = sServer;

if (sOrg == null) {
 if (typeof (ORG_UNIQUE_NAME) != &quot;undefined&quot;) {
 this.org = ORG_UNIQUE_NAME;
 }
 }

if (sServer == null) {
 this.server = window.location.protocol + &quot;//&quot; + window.location.host;
 }
 }

FetchUtil.prototype._ExecuteRequest = function (sXml, sMessage, fInternalCallback, fUserCallback) {
 var xmlhttp = new XMLHttpRequest();
 xmlhttp.open(&quot;POST&quot;, this.server + &quot;/XRMServices/2011/Organization.svc/web&quot;, (fUserCallback != null));
 xmlhttp.setRequestHeader(&quot;Accept&quot;, &quot;application/xml, text/xml, */*&quot;);
 xmlhttp.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml; charset=utf-8&quot;);
 xmlhttp.setRequestHeader(&quot;SOAPAction&quot;, &quot;http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute&quot;);

if (fUserCallback != null) {
 //asynchronous: register callback function, then send the request.
 var crmServiceObject = this;
 xmlhttp.onreadystatechange = function () {
 fInternalCallback.call(crmServiceObject, xmlhttp, fUserCallback)
 };
 xmlhttp.send(sXml);
 } else {
 //synchronous: send request, then call the callback function directly
 xmlhttp.send(sXml);
 return fInternalCallback.call(this, xmlhttp, null);
 }
 }

FetchUtil.prototype._HandleErrors = function (xmlhttp) {
 /// &lt;summary&gt;(private) Handles xmlhttp errors&lt;/summary&gt;
 if (xmlhttp.status != XMLHTTPSUCCESS) {
 var sError = &quot;Error: &quot; + xmlhttp.responseText + &quot; &quot; + xmlhttp.statusText;
 alert(sError);
 return true;
 } else {
 return false;
 }
 }

FetchUtil.prototype.Fetch = function (sFetchXml, fCallback) {
 /// &lt;summary&gt;Execute a FetchXml request. (result is the response XML)&lt;/summary&gt;
 /// &lt;param name=”sFetchXml”&gt;fetchxml string&lt;/param&gt;
 /// &lt;param name=”fCallback” optional=”true” type=”function”&gt;(Optional) Async callback function if specified. If left null, function is synchronous &lt;/param&gt;

var request = &quot;&lt;s:Envelope xmlns:s=\&quot;http://schemas.xmlsoap.org/soap/envelope/\&quot;&gt;&quot;;
 request += &quot;&lt;s:Body&gt;&quot;;

request += '&lt;Execute xmlns=&quot;http://schemas.microsoft.com/xrm/2011/Contracts/Services&quot;&gt;' + '&lt;request i:type=&quot;b:RetrieveMultipleRequest&quot; ' + ' xmlns:b=&quot;http://schemas.microsoft.com/xrm/2011/Contracts&quot; ' + ' xmlns:i=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;' + '&lt;b:Parameters xmlns:c=&quot;http://schemas.datacontract.org/2004/07/System.Collections.Generic&quot;&gt;' + '&lt;b:KeyValuePairOfstringanyType&gt;' + '&lt;c:key&gt;Query&lt;/c:key&gt;' + '&lt;c:value i:type=&quot;b:FetchExpression&quot;&gt;' + '&lt;b:Query&gt;';

request += CrmEncodeDecode.CrmXmlEncode(sFetchXml);

request += '&lt;/b:Query&gt;' + '&lt;/c:value&gt;' + '&lt;/b:KeyValuePairOfstringanyType&gt;' + '&lt;/b:Parameters&gt;' + '&lt;b:RequestId i:nil=&quot;true&quot;/&gt;' + '&lt;b:RequestName&gt;RetrieveMultiple&lt;/b:RequestName&gt;' + '&lt;/request&gt;' + '&lt;/Execute&gt;';

request += '&lt;/s:Body&gt;&lt;/s:Envelope&gt;';

return this._ExecuteRequest(request, &quot;Fetch&quot;, this._FetchCallback, fCallback);
 }

FetchUtil.prototype._FetchCallback = function (xmlhttp, callback) {
 ///&lt;summary&gt;(private) Fetch message callback.&lt;/summary&gt;
 //xmlhttp must be completed
 if (xmlhttp.readyState != XMLHTTPREADY) {
 return;
 }

//check for server errors
 if (this._HandleErrors(xmlhttp)) {
 return;
 }

var sFetchResult = xmlhttp.responseXML.selectSingleNode(&quot;//a:Entities&quot;).xml;

var resultDoc = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
 resultDoc.async = false;
 resultDoc.loadXML(sFetchResult);

//parse result xml into array of jsDynamicEntity objects
 var results = new Array(resultDoc.firstChild.childNodes.length);

for (var i = 0; i &lt; resultDoc.firstChild.childNodes.length; i++) {
 var oResultNode = resultDoc.firstChild.childNodes[i];
 var jDE = new jsDynamicEntity();
 var obj = new Object();

for (var j = 0; j &lt; oResultNode.childNodes.length; j++) {
 switch (oResultNode.childNodes[j].baseName) {
 case &quot;Attributes&quot;:
 var attr = oResultNode.childNodes[j];

for (var k = 0; k &lt; attr.childNodes.length; k++) {

// Establish the Key for the Attribute
 var sKey = attr.childNodes[k].firstChild.text;
 var sType = '';

// Determine the Type of Attribute value we should expect
 for (var l = 0; l &lt; attr.childNodes[k].childNodes[1].attributes.length; l++) {
 if (attr.childNodes[k].childNodes[1].attributes[l].baseName == 'type') {
 sType = attr.childNodes[k].childNodes[1].attributes[l].text;
 }
 }

switch (sType) {
 case &quot;a:OptionSetValue&quot;:
 var entOSV = new jsOptionSetValue();
 entOSV.type = sType;
 entOSV.value = attr.childNodes[k].childNodes[1].text;
 obj[sKey] = entOSV;
 break;

case &quot;a:EntityReference&quot;:
 var entRef = new jsEntityReference();
 entRef.type = sType;
 entRef.guid = attr.childNodes[k].childNodes[1].childNodes[0].text;
 entRef.logicalName = attr.childNodes[k].childNodes[1].childNodes[1].text;
 entRef.name = attr.childNodes[k].childNodes[1].childNodes[2].text;
 obj[sKey] = entRef;
 break;

default:
 var entCV = new jsCrmValue();
 entCV.type = sType;
 entCV.value = attr.childNodes[k].childNodes[1].text;
 obj[sKey] = entCV;

break;
 }
 }

jDE.attributes = obj;
 break;

case &quot;Id&quot;:
 jDE.guid = oResultNode.childNodes[j].text;
 break;

case &quot;LogicalName&quot;:
 jDE.logicalName = oResultNode.childNodes[j].text;
 break;

case &quot;FormattedValues&quot;:
 var foVal = oResultNode.childNodes[j];

for (var k = 0; k &lt; foVal.childNodes.length; k++) {
 // Establish the Key, we are going to fill in the formatted value of the already found attribute
 var sKey = foVal.childNodes[k].firstChild.text;

jDE.attributes[sKey].formattedValue = foVal.childNodes[k].childNodes[1].text;
 }
 break;
 }
 }
 results[i] = jDE;
 }

//return entities
 if (callback != null) callback(results);
 else return results;
 }

function jsDynamicEntity(gID, sLogicalName) {
 this.guid = gID;
 this.logicalName = sLogicalName;
 this.attributes = new Object();
 }

function jsCrmValue(sType, sValue) {
 this.type = sType;
 this.value = sValue;
 }

function jsEntityReference(gID, sLogicalName, sName) {
 this.guid = gID;
 this.logicalName = sLogicalName;
 this.name = sName;
 this.type = 'EntityReference';
 }

function jsOptionSetValue(iValue, sFormattedValue) {
 this.value = iValue;
 this.formattedValue = sFormattedValue;
 this.type = 'OptionSetValue';
 }
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/kendo-ui/'>Kendo UI</a>, <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/kendo-ui/'>Kendo UI</a>, <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=539&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/09/23/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint-sample-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 publish customizations failed after successful import</title>
		<link>http://zhongchenzhou.wordpress.com/2012/09/22/dynamics-crm-2011-publish-customizations-failed-after-successful-import/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/09/22/dynamics-crm-2011-publish-customizations-failed-after-successful-import/#comments</comments>
		<pubDate>Sat, 22 Sep 2012 09:19:35 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=536</guid>
		<description><![CDATA[I have run into this problem before, we can successfully import one solution package but the publish failed with a generic error. This is because the solution package is large and the SQL Server is slow and someone enabled CRM &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/09/22/dynamics-crm-2011-publish-customizations-failed-after-successful-import/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=536&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have run into this problem before, we can successfully import one solution package but the publish failed with a generic error.</p>
<p>This is because the solution package is large and the SQL Server is slow and someone enabled CRM Server tracing.</p>
<p>I have find a solution from this link: <a href="http://blogs.msdn.com/b/darrenliu/archive/2011/07/08/crm-2011-cannot-publish-customizations-after-import.aspx">http://blogs.msdn.com/b/darrenliu/archive/2011/07/08/crm-2011-cannot-publish-customizations-after-import.aspx</a></p>
<p>The cause for this problem is mentioned in that blog: &#8220;CRM has a default timeout value of 300 seconds = 5 minutes. If any process takes more than 5 minutes, it’ll stop.&#8221;</p>
<p>This is also mentioned in the SDK as well. <a href="http://msdn.microsoft.com/en-us/library/gg334495.aspx#BKMK_MaxSizeOfSolution">http://msdn.microsoft.com/en-us/library/gg334495.aspx#BKMK_MaxSizeOfSolution</a></p>
<p>Change the maximum allowed size by editing the &lt;httpRuntime&gt; element in the web.config file for the application. Edit the executionTimeout and maxRequestLength attributes to allow for the necessary size.</p>
<p>The solution mentioned in the blog will solve the problem as well, but it is a bit outdated.</p>
<p>Dynamics CRM 2011 web.config file use location element, so we can fix the problem by update root web.config file.</p>
<p>One of the fix mentioned in that post might be already fix depend on your Roll Up version.</p>
<p>The complete steps are listed below:</p>
<ol>
<li>On the CRM application server, open Internet Information Services (IIS) Manager.</li>
<li>Expand the server name, and then expand Web Sites.</li>
<li>Right-click the Microsoft CRM Web site, and then click Open.</li>
<li>Right-click the Web.config file, click Open With, and then click Notepad.</li>
<li>In Notepad, find</li>
</ol>
<pre class="brush: xml; title: ; notranslate">

&lt;system.web&gt;
 &lt;httpRuntime executionTimeout=&quot;300&quot; maxRequestLength=&quot;32768&quot; requestValidationMode=&quot;3.0&quot; encoderType=&quot;Microsoft.Crm.CrmHttpEncoder, Microsoft.Crm&quot; /&gt;

</pre>
<p>change to</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;system.web&gt;
 &lt;httpRuntime executionTimeout=&quot;300&quot; maxRequestLength=&quot;32768&quot; requestValidationMode=&quot;3.0&quot; encoderType=&quot;Microsoft.Crm.CrmHttpEncoder, Microsoft.Crm&quot; /&gt;

</pre>
<p>find</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;location path=&quot;MSCRMServices&quot;&gt;
 &lt;system.web&gt;
 &lt;httpRuntime maxRequestLength=&quot;8192&quot; /&gt;

</pre>
<p>change to</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;location path=&quot;MSCRMServices&quot;&gt;
 &lt;system.web&gt;
 &lt;httpRuntime maxRequestLength=&quot;32768&quot; /&gt;

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=536&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/09/22/dynamics-crm-2011-publish-customizations-failed-after-successful-import/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 update help server url</title>
		<link>http://zhongchenzhou.wordpress.com/2012/09/12/dynamics-crm-2011-update-help-server-url/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/09/12/dynamics-crm-2011-update-help-server-url/#comments</comments>
		<pubDate>Wed, 12 Sep 2012 06:58:48 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=533</guid>
		<description><![CDATA[PowerShell C# Filed under: Microsoft Dynamics CRM Tagged: Microsoft Dynamics CRM<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=533&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>PowerShell</p>
<pre class="brush: plain; title: ; notranslate">

PS &gt; Add-PSSnapin Microsoft.Crm.PowerShell
 PS &gt; $web = Get-CrmSetting WebAddressSettings
 PS &gt; $web.HelpServerUrl = &quot;&quot;
 PS &gt; Set-CrmSetting $web

</pre>
<p>C#</p>
<pre class="brush: csharp; title: ; notranslate">

var service = Microsoft.Xrm.Sdk.Deployment.Proxy.ProxyClientHelper.CreateClient(new System.Uri(&quot;http://crm2011:5555/XRMDeployment/2011/Deployment.svc&quot;));

var webAddressSettings = (Microsoft.Xrm.Sdk.Deployment.WebAddressSettings)service.Retrieve(Microsoft.Xrm.Sdk.Deployment.DeploymentEntityType.WebAddressSettings, null);

webAddressSettings.HelpServerUrl = &quot;http://crm2011:5555&quot;;

service.Update(webAddressSettings);

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=533&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/09/12/dynamics-crm-2011-update-help-server-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 10: Microsoft Fakes with workflow activity</title>
		<link>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-10-microsoft-fakes-with-workflow-activity/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-10-microsoft-fakes-with-workflow-activity/#comments</comments>
		<pubDate>Fri, 03 Aug 2012 09:24:55 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=519</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes Unit test CRM workflow activity is similar to unit &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-10-microsoft-fakes-with-workflow-activity/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=519&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>Unit test CRM workflow activity is similar to unit test CRM plugin in terms of the interface we have to mock. There are three distinct points in any code activity unit test, first is how to correctly invoke Execute method since it is protected, second is how to pass in the InArgument parameters and the last is how to pass in required service as extensions.</p>
<h2>1. Correctly invoke CodeActivity.Execute(CodeActivityContext executionContext)</h2>
<p>Since CodeActivity.Execute(CodeActivityContext executionContext) is protected, the correct way to invoke is method is to construct an instance of System.Activities.WorkflowInvoker and pass in an instance of custom code workflow activity. we can call the Invoke method on the WorkflowInvoker instance to trigger the execution of CodeActivity.Execute method.</p>
<pre class="brush: csharp; title: ; notranslate">

AddMemberTeamActivity target = new AddMemberTeamActivity();

var invoker = new WorkflowInvoker(target);

var outputs = invoker.Invoke(inputs);</pre>
<h2>2. Correctly pass in InArgument&lt;T&gt; properties</h2>
<p>the InArgument&lt;T&gt; properties need to be passed in as a dictionary when call WorkflowInvoker.Invoke method</p>
<pre class="brush: csharp; title: ; notranslate">

var inputs = new Dictionary&lt;string, object&gt;
 {
 { &quot;User&quot;, new EntityReference(&quot;systemuser&quot;, expectedUserId) },
 { &quot;Team&quot;, new EntityReference(&quot;team&quot;, expectedTeamId) }
 };

var outputs = invoker.Invoke(inputs);

</pre>
<h2>3. Pass in required service as extensions</h2>
<p>required service can be added to WorkflowInvoker.Extensions property</p>
<pre class="brush: csharp; title: ; notranslate">

var invoker = new WorkflowInvoker(target);
 invoker.Extensions.Add&lt;ITracingService&gt;(() =&gt; tracingService);
 invoker.Extensions.Add&lt;IWorkflowContext&gt;(() =&gt; workflowContext);
 invoker.Extensions.Add&lt;IOrganizationServiceFactory&gt;(() =&gt; factory);

</pre>
<p><strong>Code Under Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public sealed class AddMemberTeamActivity : CodeActivity
 {
 [RequiredArgument]
 [Input(&quot;User to Add&quot;)]
 [ReferenceTarget(&quot;systemuser&quot;)]
 public InArgument&lt;EntityReference&gt; User { get; set; }

[RequiredArgument]
 [Input(&quot;Team to Add To&quot;)]
 [ReferenceTarget(&quot;team&quot;)]
 public InArgument&lt;EntityReference&gt; Team { get; set; }

/// &lt;summary&gt;
 /// Executes the workflow activity.
 /// &lt;/summary&gt;
 /// &lt;param name=&quot;executionContext&quot;&gt;The execution context.&lt;/param&gt;
 protected override void Execute(CodeActivityContext executionContext)
 {
 // Create the tracing service
 ITracingService tracingService = executionContext.GetExtension&lt;ITracingService&gt;();

if (tracingService == null)
 {
 throw new InvalidPluginExecutionException(&quot;Failed to retrieve tracing service.&quot;);
 }

tracingService.Trace(&quot;Entered AddMemberTeamActivity.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}&quot;,
 executionContext.ActivityInstanceId,
 executionContext.WorkflowInstanceId);

// Create the context
 IWorkflowContext context = executionContext.GetExtension&lt;IWorkflowContext&gt;();

if (context == null)
 {
 throw new InvalidPluginExecutionException(&quot;Failed to retrieve workflow context.&quot;);
 }

tracingService.Trace(&quot;AddMemberTeamActivity.Execute(), Correlation Id: {0}, Initiating User: {1}&quot;,
 context.CorrelationId,
 context.InitiatingUserId);

IOrganizationServiceFactory serviceFactory = executionContext.GetExtension&lt;IOrganizationServiceFactory&gt;();
 IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

try
 {
 EntityReference user = this.User.Get(executionContext);
 EntityReference team = this.Team.Get(executionContext);

if (!IsMemberInTeam(service, team.Id, user.Id))
 {
 OrganizationRequest request = new AddMembersTeamRequest { MemberIds = new Guid[] { user.Id }, TeamId = team.Id };

var response = service.Execute(request) as AddMembersTeamResponse;
 }
 }
 catch (FaultException&lt;OrganizationServiceFault&gt; e)
 {
 tracingService.Trace(&quot;Exception: {0}&quot;, e.ToString());

// Handle the exception.
 throw;
 }

tracingService.Trace(&quot;Exiting AddMemberTeamActivity.Execute(), Correlation Id: {0}&quot;, context.CorrelationId);
 }

internal bool IsMemberInTeam(IOrganizationService service, Guid teamId, Guid memberId)
 {
 OrganizationServiceContext context = new OrganizationServiceContext(service);

var query = from relationship in context.CreateQuery(&quot;teammembership&quot;)
 where relationship.GetAttributeValue&lt;Guid&gt;(&quot;teamid&quot;) == teamId
 &amp;&amp; relationship.GetAttributeValue&lt;Guid&gt;(&quot;systemuserid&quot;) == memberId
 select relationship;

return query.FirstOrDefault() != null;
 }
 }

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

[TestClass]
 public class AddMemberTeamActivityTest
 {
 [TestMethod]
 public void ExecuteTest()
 {
 //
 // Arrange
 //
 Guid actualUserId = Guid.NewGuid();
 Guid actualTeamId = Guid.NewGuid();
 var workflowUserId = Guid.NewGuid();
 var workflowCorrelationId = Guid.NewGuid();
 var workflowInitiatingUserId = Guid.NewGuid();

// IOrganizationService
 var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
 service.ExecuteOrganizationRequest = r =&gt;
 {
 AddMembersTeamRequest request = r as AddMembersTeamRequest;
 actualUserId = request.MemberIds[0];
 actualTeamId = request.TeamId;
 return new AddMembersTeamResponse();
 };

// IWorkflowContext
 var workflowContext = new Microsoft.Xrm.Sdk.Workflow.Fakes.StubIWorkflowContext();
 workflowContext.UserIdGet = () =&gt;
 {
 return workflowUserId;
 };
 workflowContext.CorrelationIdGet = () =&gt;
 {
 return workflowCorrelationId;
 };
 workflowContext.InitiatingUserIdGet = () =&gt;
 {
 return workflowInitiatingUserId;
 };

// ITracingService
 var tracingService = new Microsoft.Xrm.Sdk.Fakes.StubITracingService();
 tracingService.TraceStringObjectArray = (f, o) =&gt;
 {
 Debug.WriteLine(f, o);
 };

// IOrganizationServiceFactory
 var factory = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationServiceFactory();
 factory.CreateOrganizationServiceNullableOfGuid = id =&gt;
 {
 return service;
 };

var expectedUserId = Guid.NewGuid();
 var expectedTeamId = Guid.NewGuid();

AddMemberTeamActivity target = new AddMemberTeamActivity();
 using (ShimsContext.Create())
 {
 var fakeTarget = new DynamicsCRMUnitTest.Workflow.Fakes.ShimAddMemberTeamActivity(target);
 fakeTarget.IsMemberInTeamIOrganizationServiceGuidGuid = (svc, teamId, memberId) =&gt;
 {
 return false;
 };

var invoker = new WorkflowInvoker(target);
 invoker.Extensions.Add&lt;ITracingService&gt;(() =&gt; tracingService);
 invoker.Extensions.Add&lt;IWorkflowContext&gt;(() =&gt; workflowContext);
 invoker.Extensions.Add&lt;IOrganizationServiceFactory&gt;(() =&gt; factory);

var inputs = new Dictionary&lt;string, object&gt;
 {
 { &quot;User&quot;, new EntityReference(&quot;systemuser&quot;, expectedUserId) },
 { &quot;Team&quot;, new EntityReference(&quot;team&quot;, expectedTeamId) }
 };

//
 // Act
 //
 var outputs = invoker.Invoke(inputs);
 }

//
 // Assert
 //
 Assert.AreEqual(expectedUserId, actualUserId);
 Assert.AreEqual(expectedTeamId, actualTeamId);
 }

[TestMethod]
 public void IsMemberInTeamTest()
 {
 //
 // Arrange
 //
 Guid userId = Guid.NewGuid();
 Guid teamId = Guid.NewGuid();
 bool expected = true;

AddMemberTeamActivity target = new AddMemberTeamActivity();

// IOrganizationService
 var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
 service.ExecuteOrganizationRequest = r =&gt;
 {
 List&lt;Entity&gt; entities = new List&lt;Entity&gt;
 {
 new Entity()
 };

var response = new RetrieveMultipleResponse
 {
 Results = new ParameterCollection
 {
 { &quot;EntityCollection&quot;, new EntityCollection(entities) }
 }
 };

return response;
 };

//
 // Act
 //
 var actual = target.IsMemberInTeam(service, teamId, userId);

//
 // Assert
 //
 Assert.AreEqual(expected, actual);
 }
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=519&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-10-microsoft-fakes-with-workflow-activity/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 9: Microsoft Fakes with CRM plugin</title>
		<link>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-9-microsoft-fakes-with-crm-plugin/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-9-microsoft-fakes-with-crm-plugin/#comments</comments>
		<pubDate>Fri, 03 Aug 2012 08:57:12 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=516</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes Unit test CRM plugin is straightforward as well, it &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-9-microsoft-fakes-with-crm-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=516&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>Unit test CRM plugin is straightforward as well, it is just a bit tedious. IPlugin.Execute only accept one parameter which is IServiceProvider. Through IServiceProvider we can retrieve at least 3 interface and we need to set up 5 interface, which will be IOrganizationService, IPluginExecutionContext, ITracingService, IOrganizationServiceFactory and IServiceProvider.</p>
<p>Suppose we have a sample Dynamics CRM plugin, which is called after a contact is created within Dynamics CRM, if the parent customer is set to an account, the number of employees attribute of that account will be increased by one.</p>
<p><strong>Code Under Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public class Plugin : IPlugin
 {
 private string _unsecure, _secure;

/// &lt;summary&gt;
 /// Alias of the image registered for the snapshot of the
 /// primary entity's attributes after the core platform operation executes.
 /// The image contains the following attributes:
 /// parentcustomerid
 ///
 /// Note: Only synchronous post-event and asynchronous registered plug-ins
 /// have PostEntityImages populated.
 /// &lt;/summary&gt;
 private readonly string postImageAlias = &quot;PostCreateImage&quot;;

public Plugin(string unsecure, string secure)
 {
 _unsecure = unsecure;
 _secure = secure;
 }

public void Execute(IServiceProvider serviceProvider)
 {
 // Obtain the execution context service from the service provider.
 var pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (pluginExecutionContext.Stage == 40 &amp;&amp; pluginExecutionContext.MessageName == &quot;Create&quot; &amp;&amp; pluginExecutionContext.PrimaryEntityName == &quot;contact&quot;)
 {
 // Obtain the tracing service from the service provider.
 var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

// Obtain the Organization Service factory service from the service provider
 IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

// Use the factory to generate the Organization Service.
 var organizationService = factory.CreateOrganizationService(pluginExecutionContext.UserId);

Entity postImageEntity = (pluginExecutionContext.PostEntityImages != null &amp;&amp; pluginExecutionContext.PostEntityImages.Contains(this.postImageAlias)) ? pluginExecutionContext.PostEntityImages[this.postImageAlias] : null;

// when a contact is created with parent account, increase number of employees for that account
 if (postImageEntity != null &amp;&amp; postImageEntity.Contains(&quot;parentcustomerid&quot;))
 {
 EntityReference parentCustomer = postImageEntity.GetAttributeValue&lt;EntityReference&gt;(&quot;parentcustomerid&quot;);

if (parentCustomer != null &amp;&amp; parentCustomer.LogicalName.ToLowerInvariant() == &quot;account&quot;)
 {
 tracingService.Trace(&quot;Parent account id: {0}.&quot;, parentCustomer.Id);

Entity parentAccount = organizationService.Retrieve(&quot;account&quot;, parentCustomer.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(&quot;numberofemployees&quot;));

int numberOfEmployees = 0;
 if (parentAccount.Contains(&quot;numberofemployees&quot;))
 {
 numberOfEmployees = parentAccount.GetAttributeValue&lt;int&gt;(&quot;numberofemployees&quot;);
 }

parentAccount[&quot;numberofemployees&quot;] = numberOfEmployees + 1;

organizationService.Update(parentAccount);
 }
 }
 }
 }
 }

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

[TestClass]
 public class PluginTest
 {
 /// &lt;summary&gt;
 ///A test for Execute
 ///&lt;/summary&gt;
 [TestMethod()]
 public void ExecuteTest()
 {
 //
 // Arrange
 //
 string unsecure = &quot;unsecure&quot;;
 string secure = &quot;secure&quot;;
 Plugin target = new Plugin(unsecure, secure);

var accountId = Guid.NewGuid();
 var previousNumber = 3;
 var expected = 4;
 var actual = 0;

// IOrganizationService
 var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
 service.RetrieveStringGuidColumnSet = (entityName, id, columns) =&gt;
 {
 return new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;)
 {
 Id = accountId,
 Attributes = { { &quot;numberofemployees&quot;, previousNumber } }
 };
 };
 service.UpdateEntity = (entity) =&gt;
 {
 actual = entity.GetAttributeValue&lt;int&gt;(&quot;numberofemployees&quot;);
 };

// IPluginExecutionContext
 var pluginExecutionContext = new Microsoft.Xrm.Sdk.Fakes.StubIPluginExecutionContext();
 pluginExecutionContext.StageGet = () =&gt; { return 40; };
 pluginExecutionContext.MessageNameGet = () =&gt; { return &quot;Create&quot;; };
 pluginExecutionContext.PrimaryEntityNameGet = () =&gt; { return &quot;contact&quot;; };
 pluginExecutionContext.PostEntityImagesGet = () =&gt;
 {
 return new EntityImageCollection
 {
 { &quot;PostCreateImage&quot;, new Microsoft.Xrm.Sdk.Entity(&quot;contact&quot;)
 {
 Attributes = { { &quot;parentcustomerid&quot;, new EntityReference(&quot;account&quot;, accountId) } }
 }
 }
 };
 };

// ITracingService
 var tracingService = new Microsoft.Xrm.Sdk.Fakes.StubITracingService();
 tracingService.TraceStringObjectArray = (f, o) =&gt;
 {
 Debug.WriteLine(f, o);
 };

// IOrganizationServiceFactory
 var factory = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationServiceFactory();
 factory.CreateOrganizationServiceNullableOfGuid = id =&gt;
 {
 return service;
 };

// IServiceProvider
 var serviceProvider = new System.Fakes.StubIServiceProvider();
 serviceProvider.GetServiceType = t =&gt;
 {
 if (t == typeof(IPluginExecutionContext))
 {
 return pluginExecutionContext;
 }
 else if (t == typeof(ITracingService))
 {
 return tracingService;
 }
 else if (t == typeof(IOrganizationServiceFactory))
 {
 return factory;
 }

return null;
 };

//
 // Act
 //
 target.Execute(serviceProvider);

//
 // Assert
 //
 Assert.AreEqual(expected, actual);
 }
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=516&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-9-microsoft-fakes-with-crm-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 8: Microsoft Fakes with IOrganizationService</title>
		<link>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-8-microsoft-fakes-with-iorganizationservice/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-8-microsoft-fakes-with-iorganizationservice/#comments</comments>
		<pubDate>Fri, 03 Aug 2012 08:40:03 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=513</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes Isolate IOrganizationService method call in unit test code should be &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-8-microsoft-fakes-with-iorganizationservice/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=513&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>Isolate IOrganizationService method call in unit test code should be very simple and straightforward, since it is a well defined interface. With Microsoft Fakes you can use the generated Stub types contained in the generated fake assembly.</p>
<p><strong>Code Under Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public class OrganizationServiceMethods
 {
 private IOrganizationService _service;

public OrganizationServiceMethods(IOrganizationService service)
 {
 _service = service;
 }

public IEnumerable&lt;Guid&gt; RetrieveAccountIdByName(string name)
 {
 QueryByAttribute query = new QueryByAttribute(&quot;account&quot;)
 {
 ColumnSet = new ColumnSet(&quot;accountid&quot;)
 };
 query.Attributes.Add(&quot;name&quot;);
 query.Values.Add(name);

var result = _service.RetrieveMultiple(query);

List&lt;Guid&gt; ids = new List&lt;Guid&gt;();

foreach (var entity in result.Entities)
 {
 ids.Add(entity.GetAttributeValue&lt;Guid&gt;(&quot;accountid&quot;));
 }

return ids;
 }
 }

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

[TestMethod]
 public void RetrieveAccountIdByNameTest()
 {
 //
 // Arrange
 //
 IEnumerable&lt;Guid&gt; actual;
 IEnumerable&lt;Guid&gt; expected = new List&lt;Guid&gt; { Guid.NewGuid(), Guid.NewGuid() };

int callCount = 0;

var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
 service.RetrieveMultipleQueryBase = (query) =&gt;
 {
 callCount++;

var results = new EntityCollection();

results.Entities.AddRange(
 new Entity(&quot;account&quot;) { Attributes = { { &quot;accountid&quot;, expected.ElementAt(0) } } },
 new Entity(&quot;account&quot;) { Attributes = { { &quot;accountid&quot;, expected.ElementAt(1) } } });

return results;
 };

OrganizationServiceMethods target = new OrganizationServiceMethods(service);

//
 // Act
 //
 actual = target.RetrieveAccountIdByName(&quot;TestName&quot;);

//
 // Assert
 //
 Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.RetrieveVersion is called once

Assert.AreEqual(expected.Count(), actual.Count());
 Assert.AreEqual(expected.ElementAt(0), actual.ElementAt(0));
 Assert.AreEqual(expected.ElementAt(1), actual.ElementAt(1));
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=513&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-8-microsoft-fakes-with-iorganizationservice/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 7: Microsoft Fakes with CrmOrganizationServiceContext through IOrganizationService</title>
		<link>http://zhongchenzhou.wordpress.com/2012/08/03/part-7-microsoft-fakes-with-crmorganizationservicecontext-through-iorganizationservice/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/08/03/part-7-microsoft-fakes-with-crmorganizationservicecontext-through-iorganizationservice/#comments</comments>
		<pubDate>Fri, 03 Aug 2012 08:18:59 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=506</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes In a previous post (Part 4: Microsoft Fakes with &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/08/03/part-7-microsoft-fakes-with-crmorganizationservicecontext-through-iorganizationservice/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=506&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>In a previous post (<a title="Dynamics CRM 2011 Unit Test Part 4: Microsoft Fakes with CrmOrganizationServiceContext" href="http://zhongchenzhou.wordpress.com/2012/07/26/dynamics-crm-2011-unit-test-part-4-microsoft-fakes-with-crmorganizationservicecontext/" target="_blank">Part 4: Microsoft Fakes with CrmOrganizationServiceContext</a>), I have describe how to use run time redirect delegate feature of Microsoft Fakes to unit test CrmOrganizationServiceContext. I consider this a direct approach since you do not need to understand the IOrganizationService API and you do not need to know all the underlining messages. If you know IOrganizationService API and underlining messages, there is also an indirect approach to unit test CrmOrganizationServiceContext, which is to mock the underlining IOrganizationService.</p>
<p>CrmOrganizationServiceContext is SDK Extensions contained in Microsoft.Xrm.Client assembly. CrmOrganizationServiceContext allows the entity objects produced by the data context to participate in the WCF Data Services framework. CrmOrganizationServiceContext provide methods from various OrganizationRequest, which means a method based implementation of the message API. These methods are defined as extension methods, to use these methods we have to include the Microsoft.Xrm.Client.Messages namespace.</p>
<p>For more information on CrmOrganizationServiceContext, see <a title="Developer Extensions Context Object Model" href="http://msdn.microsoft.com/en-us/library/gg695819.aspx" target="_blank">Developer Extensions Context Object Model</a></p>
<p>CrmOrganizationServiceContext will perform all its method work through IOrganizationService.Execute method. We need to provide an instance of IOrganizationService to construct OrganizationServiceContext, OrganizationServiceContext is going to translate LINQ to CRM query into RetrieveMultipleRequest and execute that OrganizationRequest by calling IOrganizationService.Execute. If we mock IOrganizationService properly, we can isolate LINQ to CRM query unit test.</p>
<p><strong>Code Under Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public class CrmContextMethods2
 {
 private CrmOrganizationServiceContext _crmContext;

public CrmContextMethods2(IOrganizationService service)
 {
 _crmContext = new CrmOrganizationServiceContext(service);
 }

public string RetrieveVersion()
 {
 var version = _crmContext.RetrieveVersion();

return version;
 }

public Guid CreateAccount(string name)
 {
 var entity = new Entity(&quot;account&quot;)
 {
 Attributes = new Microsoft.Xrm.Sdk.AttributeCollection
 {
 { &quot;name&quot;, name }
 }
 };

var id = _crmContext.Create(entity);

return id;
 }
 }

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

[TestClass]
 public class CrmContextMethods2Test
 {
 [TestMethod]
 public void CreateAccountTest()
 {
 //
 // Arrange
 //
 string accountName = &quot;abcabcabc&quot;;
 Guid actual;
 Guid expected = Guid.NewGuid();

int callCount = 0;
 Entity entity = null;

var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
 service.CreateEntity = e =&gt;
 {
 callCount++;
 entity = e;
 return expected;
 };

CrmContextMethods2 target = new CrmContextMethods2(service);

//
 // Act
 //
 actual = target.CreateAccount(accountName);

//
 // Assert
 //
 Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.Create is called once
 Assert.IsNotNull(entity); // verify OrganizationServiceContext.Create is called with not null object
 Assert.AreEqual(entity.LogicalName, &quot;account&quot;); // verify OrganizationServiceContext.Create is called with entity with proper entity name
 Assert.AreEqual(entity.GetAttributeValue&lt;string&gt;(&quot;name&quot;), accountName); // verify OrganizationServiceContext.Create is called with entity with proper value set on name attribute

Assert.AreEqual(expected, actual);
 }

[TestMethod]
 public void RetrieveVersionTest()
 {
 //
 // Arrange
 //
 string actual;
 string expected = &quot;5.0.9690.2243&quot;;

int callCount = 0;

var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
 service.ExecuteOrganizationRequest = r =&gt;
 {
 callCount++;

return new RetrieveVersionResponse
 {
 Results = new ParameterCollection
 {
 { &quot;Version&quot;, expected }
 }
 };
 };

CrmContextMethods2 target = new CrmContextMethods2(service);

//
 // Act
 //
 actual = target.RetrieveVersion();

//
 // Assert
 //
 Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.RetrieveVersion is called once

Assert.AreEqual(expected, actual);
 }

}

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=506&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/08/03/part-7-microsoft-fakes-with-crmorganizationservicecontext-through-iorganizationservice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Part 6: Microsoft Fakes with OrganizationServiceContext through IOrganizationService</title>
		<link>http://zhongchenzhou.wordpress.com/2012/08/02/part-6-microsoft-fakes-with-organizationservicecontext-through-iorganizationservice/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/08/02/part-6-microsoft-fakes-with-organizationservicecontext-through-iorganizationservice/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 13:28:43 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=501</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes In a previous post (Part 3: Microsoft Fakes with &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/08/02/part-6-microsoft-fakes-with-organizationservicecontext-through-iorganizationservice/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=501&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>In a previous post (<a title="Dynamics CRM 2011 Unit Test Part 3: Microsoft Fakes with OrganizationServiceContext" href="http://zhongchenzhou.wordpress.com/2012/07/13/dynamics-crm-2011-unit-test-part-3-microsoft-fakes-with-organizationservicecontext/" target="_blank">Part 3: Microsoft Fakes with OrganizationServiceContext</a>), I have describe how to use run time redirect delegate feature of Microsoft Fakes to unit test OrganizationServiceContext. I consider this a direct approach since you do not need to understand the IOrganizationService API and you do not need to know all the underlining messages. If you know IOrganizationService API and underlining messages, there is also an indirect approach to unit test OrganizationServiceContext, which is to mock the underlining IOrganizationService.</p>
<p>We need to provide an instance of IOrganizationService to construct OrganizationServiceContext, if we mock IOrganizationService properly, we can isolate OrganizationServiceContext unit test.</p>
<p><strong>Code under test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public class ContextMethods2
 {
 private OrganizationServiceContext _context;

public ContextMethods2(IOrganizationService service)
 {
 _context = new OrganizationServiceContext(service);
 }

public Guid CreateAccount(string name)
 {
 var entity = new Entity(&quot;account&quot;)
 {
 Attributes = new Microsoft.Xrm.Sdk.AttributeCollection
 {
 { &quot;name&quot;, name }
 }
 };

_context.AddObject(entity);

var results = _context.SaveChanges();

return entity.Id;
 }
 }

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

[TestClass]
 public class ContextMethods2Test
 {
 [TestMethod]
 public void CreateAccountTest()
 {
 //
 // Arrange
 //
 string accountName = &quot;abcabcabc&quot;;
 Guid actual;
 Guid expected = Guid.Empty;

int callCount = 0;
 Entity entity = null;

var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
 service.ExecuteOrganizationRequest = r =&gt;
 {
 callCount++;

var request = r as CreateRequest;
 entity = request.Target;
 expected = entity.Id;

return new CreateResponse
 {
 Results = new ParameterCollection
 {
 { &quot;id&quot;, expected }
 }
 };
 };

ContextMethods2 target = new ContextMethods2(service);

//
 // Act
 //
 actual = target.CreateAccount(accountName);

//
 // Assert
 //
 Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.AddObject is called once
 Assert.IsNotNull(entity); // verify OrganizationServiceContext.AddObject is called with not null object
 Assert.AreEqual(entity.LogicalName, &quot;account&quot;); // verify OrganizationServiceContext.AddObject is called with entity with proper entity name
 Assert.AreEqual(entity.GetAttributeValue&lt;string&gt;(&quot;name&quot;), accountName); // verify OrganizationServiceContext.AddObject is called with entity with proper value set on name attribute

Assert.AreEqual(expected, actual);
 }
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=501&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/08/02/part-6-microsoft-fakes-with-organizationservicecontext-through-iorganizationservice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 5: Microsoft Fakes with LINQ query through IOrganizationService</title>
		<link>http://zhongchenzhou.wordpress.com/2012/08/01/dynamics-crm-2011-unit-test-part-5-microsoft-fakes-with-linq-query-through-iorganizationservice/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/08/01/dynamics-crm-2011-unit-test-part-5-microsoft-fakes-with-linq-query-through-iorganizationservice/#comments</comments>
		<pubDate>Wed, 01 Aug 2012 00:39:11 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=497</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes In a previous post (Part 2: Microsoft Fakes with LINQ query), &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/08/01/dynamics-crm-2011-unit-test-part-5-microsoft-fakes-with-linq-query-through-iorganizationservice/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=497&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>In a previous post (<a title="Dynamics CRM 2011 Unit Test Part 2: Microsoft Fakes with LINQ query" href="http://zhongchenzhou.wordpress.com/2012/07/10/dynamics-crm-2011-unit-test-part-2-microsoft-fakes-with-linq-query/" target="_blank">Part 2: Microsoft Fakes with LINQ query</a>), I have describe how to use run time redirect delegate feature of Microsoft Fakes to unit test LINQ to CRM query. I consider this a direct approach since you do not need to understand the IOrganizationService API and you do not need to know all the underlining messages. If you know IOrganizationService API and underlining messages, there is also an indirect approach to unit test LINQ to CRM query, which is to mock the underlining IOrganizationService.</p>
<p>To use LINQ to query CRM data, we need to use OrganizationServiceContext or a deriving class such as CrmOrganizationServiceContext which is SDK Extensions contained in Microsoft.Xrm.Client assembly, or a deriving class created by the CrmSvcUtil tool. The OrganizationServiceContext class contains an underlying LINQ query provider that translates LINQ queries from Microsoft Visual C# or Microsoft Visual Basic .NET syntax into the query API used by Microsoft Dynamics CRM.</p>
<p>We need to provide an instance of IOrganizationService to construct OrganizationServiceContext, OrganizationServiceContext is going to translate LINQ to CRM query into RetrieveMultipleRequest and execute that OrganizationRequest by calling IOrganizationService.Execute. If we mock IOrganizationService properly, we can isolate LINQ to CRM query unit test.</p>
<p><strong>Code under test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public class LINQToCRM2
 {
 private OrganizationServiceContext _context;

public LINQToCRM2(IOrganizationService service)
 {
 _context = new OrganizationServiceContext(service);
 }

public IEnumerable&lt;Entity&gt; RetrieveAccountsByName(string name)
 {
 var query = from account in _context.CreateQuery(&quot;account&quot;)
 where account.GetAttributeValue&lt;string&gt;(&quot;name&quot;) == name
 select account;

var accountList = new List&lt;Entity&gt;();

foreach (var entity in query)
 {
 accountList.Add(entity);
 }

//We can simply call query.ToList()
 //foreach loop here is to demonstrate item Enumeration

return accountList;
 }

public Entity RetrieveAccountsById(Guid id)
 {
 var query = from account in _context.CreateQuery(&quot;account&quot;)
 where account.GetAttributeValue&lt;Guid&gt;(&quot;accountid&quot;) == id
 select account;

var accountEntity = query.FirstOrDefault();

return accountEntity;
 }
 }

</pre>
<p><strong>Unit Test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

[TestClass]
 public class LINQToCRM2Test
 {
 [TestMethod]
 public void RetrieveAccountsByNameTest()
 {
 //
 // Arrange
 //
 var entity1 = new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;);
 entity1.Id = Guid.NewGuid();
 entity1[&quot;name&quot;] = &quot;abcabcabc&quot;;

var entity2 = new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;);
 entity2.Id = Guid.NewGuid();
 entity2[&quot;name&quot;] = &quot;123123123&quot;;

var entity3 = new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;);
 entity3.Id = Guid.NewGuid();
 entity3[&quot;name&quot;] = &quot;a1b2c3a1b2c3&quot;;

var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();

service.ExecuteOrganizationRequest = r =&gt;
 {
 List&lt;Entity&gt; entities = new List&lt;Entity&gt;
 {
 entity1, entity2
 };

var response = new RetrieveMultipleResponse
 {
 Results = new ParameterCollection
 {
 { &quot;EntityCollection&quot;, new EntityCollection(entities) }
 }
 };

return response;
 };

string accountName = &quot;abcabcabc&quot;;
 IEnumerable&lt;Microsoft.Xrm.Sdk.Entity&gt; actual;
 LINQToCRM2 target = new LINQToCRM2(service);

//
 // Act
 //
 actual = target.RetrieveAccountsByName(accountName);

//
 // Assert
 //
 Assert.AreEqual(2, actual.Count());
 Assert.AreEqual(entity1, actual.ElementAt(0));
 Assert.AreEqual(entity2, actual.ElementAt(1));
 }

[TestMethod]
 public void RetrieveAccountsByIdTest()
 {
 //
 // Arrange
 //
 Guid id = Guid.NewGuid();

Microsoft.Xrm.Sdk.Entity expected = new Microsoft.Xrm.Sdk.Entity { Id = id };

var service = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();

service.ExecuteOrganizationRequest = r =&gt;
 {
 List&lt;Entity&gt; entities = new List&lt;Entity&gt;
 {
 expected
 };

var response = new RetrieveMultipleResponse
 {
 Results = new ParameterCollection
 {
 { &quot;EntityCollection&quot;, new EntityCollection(entities) }
 }
 };

return response;
 };

Microsoft.Xrm.Sdk.Entity actual;
 LINQToCRM2 target = new LINQToCRM2(service);

//
 // Act
 //
 actual = target.RetrieveAccountsById(id);

//
 // Assert
 //
 Assert.AreEqual(expected, actual);
 }
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=497&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/08/01/dynamics-crm-2011-unit-test-part-5-microsoft-fakes-with-linq-query-through-iorganizationservice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 4: Microsoft Fakes with CrmOrganizationServiceContext</title>
		<link>http://zhongchenzhou.wordpress.com/2012/07/26/dynamics-crm-2011-unit-test-part-4-microsoft-fakes-with-crmorganizationservicecontext/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/07/26/dynamics-crm-2011-unit-test-part-4-microsoft-fakes-with-crmorganizationservicecontext/#comments</comments>
		<pubDate>Thu, 26 Jul 2012 06:30:45 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=490</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes If you know IOrganizationService API and underlining messages, there &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/07/26/dynamics-crm-2011-unit-test-part-4-microsoft-fakes-with-crmorganizationservicecontext/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=490&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>If you know IOrganizationService API and underlining messages, there is also an indirect approach to unit test CrmOrganizationServiceContext, which is to mock the underlining IOrganizationService. That is discussed in another post (<a title="Part 7: Microsoft Fakes with CrmOrganizationServiceContext through IOrganizationService" href="http://zhongchenzhou.wordpress.com/2012/08/03/part-7-microsoft-fakes-with-crmorganizationservicecontext-through-iorganizationservice/" target="_blank">Part 7: Microsoft Fakes with CrmOrganizationServiceContext through IOrganizationService</a>).</p>
<h2>CrmOrganizationServiceContext</h2>
<p>CrmOrganizationServiceContext is SDK Extensions contained in Microsoft.Xrm.Client assembly. CrmOrganizationServiceContext allows the entity objects produced by the data context to participate in the WCF Data Services framework. CrmOrganizationServiceContext provide methods from various OrganizationRequest, which means a method based implementation of the message API. These methods are defined as extension methods, to use these methods we have to include the Microsoft.Xrm.Client.Messages namespace.</p>
<p>For more information on CrmOrganizationServiceContext, see <a title="Developer Extensions Context Object Model" href="http://msdn.microsoft.com/en-us/library/gg695819.aspx" target="_blank">Developer Extensions Context Object Model</a></p>
<p>Microsoft Fakes does not support CrmOrganizationServiceContext, if we try to set up a run time delegate, we will receive ShimNotSupported exception. So we can go the traditional way to extract interface and provide a wrap type around CrmOrganizationServiceContext and implement that interface.</p>
<p>Most of the methods contained within SDK extension are OrganizationServiceContext extension methods. These methods are defined in Microsoft.Xrm.Client.Messages.OrganizationServiceContextExtensions and Microsoft.Xrm.Client.OrganizationServiceContextExtensions. And I have created one Interface and a wrapper Class.</p>
<p><a href="https://gist.github.com/3180585">https://gist.github.com/3180585</a></p>
<p><a href="https://gist.github.com/3180591">https://gist.github.com/3180591</a></p>
<pre class="brush: csharp; title: ; notranslate">

namespace CrmOrganizationServiceContextExtensions
{
 public interface ICrmOrganizationServiceContext
 {
 /*
 * Microsoft.Xrm.Client.Messages.OrganizationServiceContextExtensions
 */

/*
 * Microsoft.Xrm.Client.CrmOrganizationServiceContext
 */
 }
}

</pre>
<p>&nbsp;</p>
<pre class="brush: csharp; title: ; notranslate">

namespace CrmOrganizationServiceContextExtensions
{
 public class CrmContext : CrmOrganizationServiceContext, ICrmOrganizationServiceContext
 {
 public CrmContext() : base() { }
 public CrmContext(string contextName) : base(contextName) { }
 public CrmContext(CrmConnection connection) : base(connection) { }
 public CrmContext(IOrganizationService service) : base(service) { }

private Microsoft.Xrm.Sdk.Client.OrganizationServiceContext _context;
 private Microsoft.Xrm.Sdk.Client.OrganizationServiceContext Context
 {
 get
 {
 if (_context == null)
 {
 _context = this as Microsoft.Xrm.Sdk.Client.OrganizationServiceContext;
 }

return _context;
 }
 }

/*
 * Microsoft.Xrm.Client.Messages.OrganizationServiceContextExtensions
 */

/*
 * Microsoft.Xrm.Client.OrganizationServiceContextExtensions
 */
 }
}

</pre>
<p>We can start using the Interface and wrapper Class in our code.</p>
<p><strong>Suppose we have the following code under test</strong></p>
<pre class="brush: csharp; title: ; notranslate">

public class CrmContextMethods
 {
 private ICrmOrganizationServiceContext _crmContext;

public CrmContextMethods(ICrmOrganizationServiceContext crmContext)
 {
 _crmContext = crmContext;
 }

public string RetrieveVersion()
 {
 var version = _crmContext.RetrieveVersion();

return version;
 }

public Guid CreateAccount(string name)
 {
 var entity = new Entity(&quot;account&quot;)
 {
 Attributes = new Microsoft.Xrm.Sdk.AttributeCollection
 {
 { &quot;name&quot;, name }
 }
 };

var id = _crmContext.Create(entity);

return id;
 }
 }

</pre>
<p><strong>The unit test code code could be</strong></p>
<pre class="brush: csharp; title: ; notranslate">

[TestClass]
 public class CrmContextMethodsTest
 {
 [TestMethod]
 public void CreateAccountTest()
 {
 //
 // Arrange
 //
 string accountName = &quot;abcabcabc&quot;;
 Guid actual;
 Guid expected = Guid.NewGuid();

int callCount = 0;
 Entity entity = null;

var context = new CrmOrganizationServiceContextExtensions.Fakes.StubICrmOrganizationServiceContext();
 context.CreateEntity = e =&gt;
 {
 callCount++;
 entity = e;
 return expected;
 };

CrmContextMethods target = new CrmContextMethods(context);

//
 // Act
 //
 actual = target.CreateAccount(accountName);

//
 // Assert
 //
 Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.Create is called once
 Assert.IsNotNull(entity); // verify OrganizationServiceContext.Create is called with not null object
 Assert.AreEqual(entity.LogicalName, &quot;account&quot;); // verify OrganizationServiceContext.Create is called with entity with proper entity name
 Assert.AreEqual(entity.GetAttributeValue&lt;string&gt;(&quot;name&quot;), accountName); // verify OrganizationServiceContext.Create is called with entity with proper value set on name attribute

Assert.AreEqual(expected, actual);

}

[TestMethod]
 public void RetrieveVersionTest()
 {
 //
 // Arrange
 //
 string actual;
 string expected = &quot;5.0.9690.2243&quot;;

int callCount = 0;

var context = new CrmOrganizationServiceContextExtensions.Fakes.StubICrmOrganizationServiceContext();
 context.RetrieveVersion = () =&gt;
 {
 callCount++;
 return expected;
 };

CrmContextMethods target = new CrmContextMethods(context);

//
 // Act
 //
 actual = target.RetrieveVersion();

//
 // Assert
 //
 Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.RetrieveVersion is called once

Assert.AreEqual(expected, actual);

}
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=490&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/07/26/dynamics-crm-2011-unit-test-part-4-microsoft-fakes-with-crmorganizationservicecontext/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 3: Microsoft Fakes with OrganizationServiceContext</title>
		<link>http://zhongchenzhou.wordpress.com/2012/07/13/dynamics-crm-2011-unit-test-part-3-microsoft-fakes-with-organizationservicecontext/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/07/13/dynamics-crm-2011-unit-test-part-3-microsoft-fakes-with-organizationservicecontext/#comments</comments>
		<pubDate>Fri, 13 Jul 2012 06:14:29 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=480</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes If you know IOrganizationService API and underlining messages, there &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/07/13/dynamics-crm-2011-unit-test-part-3-microsoft-fakes-with-organizationservicecontext/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=480&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>If you know IOrganizationService API and underlining messages, there is also an indirect approach to unit test OrganizationServiceContext, which is to mock the underlining IOrganizationService. That is discussed in another post (<a title="Part 6: Microsoft Fakes with OrganizationServiceContext through IOrganizationService" href="http://zhongchenzhou.wordpress.com/2012/08/02/part-6-microsoft-fakes-with-organizationservicecontext-through-iorganizationservice/" target="_blank">Dynamics CRM 2011 Unit Test Part 6: Microsoft Fakes with OrganizationServiceContext through IOrganizationService</a>).</p>
<h2>OrganizationServiceContext</h2>
<p>OrganizationServiceContext is based on the same concept as the ObjectContext Class in Entity Framework. The OrganizationServiceContext class lets you track changes, manage identities and relationships. Objects tracked by the organization service context are instances of entity types that represent data in Microsoft Dynamics CRM. You can designate actions to be performed on these objects and the service context tracks the changes. When the SaveChanges method is called, the service context instructs Microsoft Dynamics CRM to generate commands to create, update or delete the entities the tracked objects represent.</p>
<p>For more information on OrganizationServiceContext, see <a title="Use the Organization Service Context Class" href="http://msdn.microsoft.com/en-us/library/gg334504.aspx" target="_blank">Use the Organization Service Context Class</a> and <a title="OrganizationServiceContext Class" href="http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.client.organizationservicecontext.aspx" target="_blank">OrganizationServiceContext Class</a></p>
<p>The main method that we want to simulate is <strong>OrganizationServiceContext.SaveChanges()</strong>. We will need to create fakes assembly for microsoft.xrm.sdk assembly using visual studio 2012, after that we can use Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext type contained within the fake assembly to detour call to OrganizationServiceContext.SaveChanges().</p>
<pre class="brush: csharp; title: ; notranslate">var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context);
fakeContext.SaveChanges = () =&gt;
 {
 entity.Id = expected;

 // SaveChangesResultCollection only has one internal constructor
 // so we can not create a instance outside of Microsoft.Xrm.Sdk assembly
 // we will use reflection to create instances of SaveChangesResultCollection and SaveChangesResult
 var results = CreateSaveChangesResultCollection(SaveChangesOptions.None);

var request = new OrganizationRequest();
 var response = new OrganizationResponse();

results.Add(CreateSaveChangesResult(request, response));

return results;
 };
</pre>
<p>It should be very straightforward, except that SaveChangesResult and SaveChangesResultCollection only have internal constructors, we have to use reflection to create  SaveChangesResult and SaveChangesResultCollection that returned from OrganizationServiceContext.SaveChanges().</p>
<h4>Create SaveChangesResultCollection</h4>
<pre class="brush: csharp; title: ; notranslate">
private SaveChangesResultCollection CreateSaveChangesResultCollection(SaveChangesOptions option)
 {
 var con = typeof(SaveChangesResultCollection).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault();
 var results = con.Invoke(new object[] { option }) as SaveChangesResultCollection;
 return results;
 }
</pre>
<h4>Create SaveChangesResult</h4>
<pre class="brush: csharp; title: ; notranslate">
private SaveChangesResult CreateSaveChangesResult(OrganizationRequest request, OrganizationResponse response)
 {
 var con = typeof(SaveChangesResult).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault();
 var result = con.Invoke(new object[] { request, response }) as SaveChangesResult;
 return result;
 }

private SaveChangesResult CreateSaveChangesResult(OrganizationRequest request, Exception error)
 {
 var con = typeof(SaveChangesResult).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault();
 var result = con.Invoke(new object[] { request, error }) as SaveChangesResult;
 return result;
 }
</pre>
<p>Suppose we use the following code to create account in crm</p>
<pre class="brush: csharp; title: ; notranslate">
public class ContextMethods
 {
 private OrganizationServiceContext _context;

public ContextMethods(OrganizationServiceContext context)
 {
 _context = context;
 }

public Guid CreateAccount(string name)
 {
 var entity = new Entity(&quot;account&quot;)
 {
 Attributes = new Microsoft.Xrm.Sdk.AttributeCollection
 {
 { &quot;name&quot;, name }
 }
 };

_context.AddObject(entity);

var results = _context.SaveChanges();

return entity.Id;
 }
 }
</pre>
<p>The unit test code could be</p>
<pre class="brush: csharp; title: ; notranslate">
[TestClass]
 public class ContextMethodsTest
 {
 [TestMethod]
 public void CreateAccountTest()
 {
 //
 // Arrange
 //
 var connection = new CrmConnection(&quot;Crm&quot;);
 var service = new OrganizationService(connection);
 var context = new OrganizationServiceContext(service);
 using (ShimsContext.Create())
 {
 string accountName = &quot;abcabcabc&quot;;
 Guid actual;
 Guid expected = Guid.NewGuid();

int callCount = 0;
 Entity entity = null;

var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context);

fakeContext.AddObjectEntity = e =&gt;
 {
 callCount++;
 entity = e;
 };

fakeContext.SaveChanges = () =&gt;
 {
 entity.Id = expected;

 // SaveChangesResultCollection only has one internal constructor
 // so we can not create a instance outside of Microsoft.Xrm.Sdk assembly
 // we will use reflection to create instances of SaveChangesResultCollection and SaveChangesResult
 var results = CreateSaveChangesResultCollection(SaveChangesOptions.None);

var request = new OrganizationRequest();
 var response = new OrganizationResponse();

results.Add(CreateSaveChangesResult(request, response));

return results;
 };

ContextMethods target = new ContextMethods(context);

//
 // Act
 //
 actual = target.CreateAccount(accountName);

//
 // Assert
 //
 Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.AddObject is called once
 Assert.IsNotNull(entity); // verify OrganizationServiceContext.AddObject is called with not null object
 Assert.AreEqual(entity.LogicalName, &quot;account&quot;); // verify OrganizationServiceContext.AddObject is called with entity with proper entity name
 Assert.AreEqual(entity.GetAttributeValue&lt;string&gt;(&quot;name&quot;), accountName); // verify OrganizationServiceContext.AddObject is called with entity with proper value set on name attribute

 Assert.AreEqual(expected, actual);
 }
 }

private SaveChangesResultCollection CreateSaveChangesResultCollection(SaveChangesOptions option)
 {
 var con = typeof(SaveChangesResultCollection).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault();
 var results = con.Invoke(new object[] { option }) as SaveChangesResultCollection;
 return results;
 }

private SaveChangesResult CreateSaveChangesResult(OrganizationRequest request, OrganizationResponse response)
 {
 var con = typeof(SaveChangesResult).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault();
 var result = con.Invoke(new object[] { request, response }) as SaveChangesResult;
 return result;
 }

private SaveChangesResult CreateSaveChangesResult(OrganizationRequest request, Exception error)
 {
 var con = typeof(SaveChangesResult).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault();
 var result = con.Invoke(new object[] { request, error }) as SaveChangesResult;
 return result;
 }
 }
</pre>
<h2></h2>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=480&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/07/13/dynamics-crm-2011-unit-test-part-3-microsoft-fakes-with-organizationservicecontext/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 2: Microsoft Fakes with LINQ query</title>
		<link>http://zhongchenzhou.wordpress.com/2012/07/10/dynamics-crm-2011-unit-test-part-2-microsoft-fakes-with-linq-query/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/07/10/dynamics-crm-2011-unit-test-part-2-microsoft-fakes-with-linq-query/#comments</comments>
		<pubDate>Mon, 09 Jul 2012 15:00:12 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=466</guid>
		<description><![CDATA[Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: Dynamics CRM unit test using Microsoft Fakes If you know IOrganizationService API and underlining messages, there &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/07/10/dynamics-crm-2011-unit-test-part-2-microsoft-fakes-with-linq-query/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=466&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</a></p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<p>If you know IOrganizationService API and underlining messages, there is also an indirect approach to unit test LINQ to CRM query, which is to mock the underlining IOrganizationService. That is discussed in another post (<a title="Dynamics CRM 2011 Unit Test Part 5: Microsoft Fakes with LINQ query through IOrganizationService" href="http://zhongchenzhou.wordpress.com/2012/08/01/dynamics-crm-2011-unit-test-part-5-microsoft-fakes-with-linq-query-through-iorganizationservice/" target="_blank">Dynamics CRM 2011 Unit Test Part 5: Microsoft Fakes with LINQ query through IOrganizationService</a>).</p>
<h2>LINQ to CRM query</h2>
<p>Dynamics CRM 2011 supports using LINQ to query CRM data, which makes the query much more easy to write and compact. We do not need to construct a complex QueryExpression object for simple queries.</p>
<p>To use LINQ to query CRM data, we need to use OrganizationServiceContext or a deriving class such as CrmOrganizationServiceContext which is SDK Extensions contained in Microsoft.Xrm.Client assembly, or a deriving class created by the CrmSvcUtil tool. The OrganizationServiceContext class contains an underlying LINQ query provider that translates LINQ queries from Microsoft Visual C# or Microsoft Visual Basic .NET syntax into the query API used by Microsoft Dynamics CRM.</p>
<p>For more information on Build Queries with LINQ, please see <a title="Build Queries with LINQ (.NET Language-Integrated Query)" href="http://msdn.microsoft.com/en-us/library/gg328028.aspx" target="_blank">Build Queries with LINQ (.NET Language-Integrated Query)</a></p>
<p>When test LINQ to CRM query, there are some challengers. First OrganizationServiceContext does not implement any interface or abstract class, second LINQ to CRM query involved some method in System.Linq namespace.</p>
<pre class="brush: csharp; title: ; notranslate">

public class OrganizationServiceContext : IDisposable
public class CrmOrganizationServiceContext : OrganizationServiceContext, IInitializable, IOrganizationService, IUpdatable, IExpandProvider, IOrganizationServiceContainer
public partial class ServiceContext: Microsoft.Xrm.Sdk.Client.OrganizationServiceContext

</pre>
<p>The common method to test such class is to abstract an interface and use that interface in the calling code, but this method need to write more code and carefully design of the code. (This will be discussed in later posts with Rhino Mocks and Moq). A better approach is to use either Microsoft Fakes test framework or Microsoft Moles test framework. We will focus on Microsoft Fakes test framework in this post, Microsoft Moles will be introduced in later post.</p>
<p>Microsoft Fakes test framework is included in Visual Studio 2012 and can generate fakes assembly which contains shim types.  Shim types allow detouring of hard-coded dependencies on static or non-overridable methods.</p>
<p>For more information on Microsoft Fakes, please see <a title="Isolating Unit Test Methods with Microsoft Fakes" href="http://msdn.microsoft.com/en-us/library/tfs/hh549175(v=vs.110)" target="_blank">Isolating Unit Test Methods with Microsoft Fakes</a></p>
<p>Let&#8217;s see a few unit test sample which use Microsoft Fakes</p>
<p>This sample use SDK Extensions contained in Microsoft.Xrm.Client assembly. For more information on Dynamics CRM SDK Extensions, please see S<a title="SDK Extensions for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online" href="http://msdn.microsoft.com/en-us/library/hh547449" target="_blank">DK Extensions for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online</a></p>
<p><strong>We need to generate fake assembly for microsoft.xrm.sdk.dll and System.Core.dll</strong></p>
<h3>Enumeration</h3>
<p>Suppose we have the following class</p>
<pre class="brush: csharp; title: ; notranslate">

public class LINQToCRM
 {
 private OrganizationServiceContext _context;

public LINQToCRM(OrganizationServiceContext context)
 {
 _context = context;
 }

public IEnumerable RetrieveAccountsByName(string name)
 {
 var query = from account in _context.CreateQuery(&quot;account&quot;)
 where account.GetAttributeValue(&quot;name&quot;) == name
 select account;

var accountList = new List();

foreach(var entity in query)
 {
 accountList.Add(entity);
 }

//We can simply call query.ToList()
 //foreach loop here is to demonstrate item Enumeration

return accountList;
 }
}

</pre>
<p>There are two external dependencies in this code fragment. First is <strong>OrganizationServiceContext.CreateQuery</strong>, Second is <strong>foreach(var entity in query)</strong>.</p>
<p>In this case we have to detour <strong>OrganizationServiceContext.CreateQuery </strong>and <strong>System.Linq.EnumerableQuery&lt;Microsoft.Xrm.Sdk.Entity&gt;.GetEnumerator</strong> to user defined delegate.</p>
<p><strong>OrganizationServiceContext.CreateQuery </strong>is the place we can simulate Dynamics CRM data store. Entities returned from this method should be considered to be retrieved from Dynamics CRM, and the result will be further filtered by the rest of the LINQ operators.</p>
<p><strong><strong>System.Linq.EnumerableQuery&lt;Microsoft.Xrm.Sdk.Entity&gt;.GetEnumerator</strong> </strong>is the place we return the final result for the query, regardless of the data store or any LINQ operator.</p>
<pre class="brush: csharp; title: ; notranslate">

[TestMethod]
 public void RetrieveAccountsByNameTest()
 {
 var connection = new CrmConnection(&quot;Crm&quot;);
 var service = new OrganizationService(connection);
 var context = new OrganizationServiceContext(service);
 using (ShimsContext.Create())
 {
 var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context);
 LINQToCRM target = new LINQToCRM(context);

var entity1 = new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;);
 entity1.Id = Guid.NewGuid();
 entity1[&quot;name&quot;] = &quot;abcabcabc&quot;;

var entity2 = new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;);
 entity2.Id = Guid.NewGuid();
 entity2[&quot;name&quot;] = &quot;123123123&quot;;

var entity3 = new Microsoft.Xrm.Sdk.Entity(&quot;account&quot;);
 entity3.Id = Guid.NewGuid();
 entity3[&quot;name&quot;] = &quot;a1b2c3a1b2c3&quot;;

fakeContext.CreateQueryString = (entityName) =&gt;
 {
 return new System.Linq.EnumerableQuery(new Microsoft.Xrm.Sdk.Entity[] { entity1, entity2, entity3 });
 };

IEnumerable expected = new List { entity1, entity2 };

System.Linq.Fakes.ShimEnumerableQuery.AllInstances.GetEnumerator = (a) =&gt;
 {
 return expected.GetEnumerator();
 };

string accountName = &quot;abcabcabc&quot;;
 IEnumerable actual;
 actual = target.RetrieveAccountsByName(accountName);

Assert.AreEqual(expected.Count(), actual.Count());
 Assert.AreEqual(expected.ElementAt(0), actual.ElementAt(0));
 Assert.AreEqual(expected.ElementAt(1), actual.ElementAt(1));
 }
 }

</pre>
<h3>FirstOrDefault method</h3>
<p>If we do not need to enumerate the result but want to call FirstOrDefault method, we can detour <strong>System.Linq.Queryable.FirstOrDefault&lt;Microsoft.Xrm.Sdk.Entity&gt;</strong> to user defined delegate.</p>
<p>Suppose we have the following code under test</p>
<pre class="brush: csharp; title: ; notranslate">

public class LINQToCRM
 {
 private OrganizationServiceContext _context;

public LINQToCRM(OrganizationServiceContext context)
 {
 _context = context;
 }

public Entity RetrieveAccountsById(Guid id)

{
 var query = from account in _context.CreateQuery(&quot;account&quot;)
 where account.GetAttributeValue(&quot;accountid&quot;) == id
 select account;

var accountEntity = query.FirstOrDefault();

return accountEntity;
 }
 }

</pre>
<p>The unit test would be similar to the following</p>
<pre class="brush: csharp; title: ; notranslate">

[TestMethod]
 public void RetrieveAccountsByIdTest()
 {
 var connection = new CrmConnection(&quot;Crm&quot;);
 var service = new OrganizationService(connection);
 var context = new OrganizationServiceContext(service);
 using (ShimsContext.Create())
 {
 var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context);
 LINQToCRM target = new LINQToCRM(context);

fakeContext.CreateQueryString = (entityName) =&gt;
 {
 return new System.Linq.EnumerableQuery(new Microsoft.Xrm.Sdk.Entity[] { });
 };

Guid id = Guid.NewGuid();

Microsoft.Xrm.Sdk.Entity expected = new Microsoft.Xrm.Sdk.Entity();

System.Linq.Fakes.ShimQueryable.FirstOrDefaultOf1IQueryableOfM0((a) =&gt;
 {
 expected.Id = id;
 return expected;
 });

Microsoft.Xrm.Sdk.Entity actual;

actual = target.RetrieveAccountsById(id);

Assert.AreEqual(expected, actual);
 }
 }

</pre>
<h3>Other common LINQ methods</h3>
<p>Other common LINQ methods could also be find in System.Linq.Queryable class, so that we can use the generated shim class <strong>System.Linq.Fakes.ShimQueryable</strong> to detour required methods call to user defined delegate.</p>
<p><strong>Note:</strong> Not all the methods are supported by Dynamics CRM. (e.g. Any is not supported)</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=466&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/07/10/dynamics-crm-2011-unit-test-part-2-microsoft-fakes-with-linq-query/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents</title>
		<link>http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/#comments</comments>
		<pubDate>Sun, 08 Jul 2012 04:49:45 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=463</guid>
		<description><![CDATA[Introduction This is the first post of a series containing collections of patterns and code fragments showing how various unit frameworks can be used in Dynamics CRM 2011 development. Unit test with server side components, (web service, plugin, workflow), will &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=463&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>This is the first post of a series containing collections of patterns and code fragments showing how various unit frameworks can be used in Dynamics CRM 2011 development.</p>
<p>Unit test with server side components, (web service, plugin, workflow), will be explained with Microsoft Fakes, Rhino Mocks and Moq.</p>
<p>Unit test with client side JavaScript will be explained with QUnit.</p>
<p>The complete sample code using Microsoft Fakes can be downloaded from MSDN sample gallery: <a title="Dynamics CRM unit test using Microsoft Fakes" href="http://code.msdn.microsoft.com/Dynamics-CRM-unit-test-93be6676" target="_blank">Dynamics CRM unit test using Microsoft Fakes</a></p>
<h2>Series Contents</h2>
<p><a title="Dynamics CRM 2011 Unit Test Part 1: Introduction and Series Contents" href="http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/" target="_blank">Part 1: Introduction and Series Contents</a></p>
<ul>
<li>Introduces the topics that will be covered in the series</li>
</ul>
<p><a title="Dynamics CRM 2011 Unit Test Part 2: Microsoft Fakes with LINQ query" href="http://zhongchenzhou.wordpress.com/2012/07/10/dynamics-crm-2011-unit-test-part-2-microsoft-fakes-with-linq-query/" target="_blank">Part 2: Microsoft Fakes with LINQ query</a></p>
<ul>
<li>Unit test CRM LINQ query</li>
<li>Mock System.Linq namespace</li>
<li>Mock Mock OrganizationServiceContext.CreateQuery</li>
</ul>
<div><a title="Dynamics CRM 2011 Unit Test Part 3: Microsoft Fakes with OrganizationServiceContext" href="http://zhongchenzhou.wordpress.com/2012/07/13/dynamics-crm-2011-unit-test-part-3-microsoft-fakes-with-organizationservicecontext/" target="_blank">Part 3: Microsoft Fakes with OrganizationServiceContext</a></div>
<div>
<ul>
<li>Mock OrganizationServiceContext</li>
<li>Create SaveChangesResultCollection</li>
<li>Create SaveChangesResult</li>
</ul>
</div>
<p><a title="Dynamics CRM 2011 Unit Test Part 4: Microsoft Fakes with CrmOrganizationServiceContext" href="http://zhongchenzhou.wordpress.com/2012/07/26/dynamics-crm-2011-unit-test-part-4-microsoft-fakes-with-crmorganizationservicecontext/" target="_blank">Part 4: Microsoft Fakes with CrmOrganizationServiceContext</a></p>
<ul>
<li>Mock CrmOrganizationServiceContext</li>
</ul>
<p><a title="Dynamics CRM 2011 Unit Test Part 5: Microsoft Fakes with LINQ query through IOrganizationService" href="http://zhongchenzhou.wordpress.com/2012/08/01/dynamics-crm-2011-unit-test-part-5-microsoft-fakes-with-linq-query-through-iorganizationservice/" target="_blank">Part 5: Microsoft Fakes with LINQ query through IOrganizationService</a></p>
<ul>
<li>Mock IOrganizationService to isolate LINQ to CRM query</li>
</ul>
<p><a title="Part 6: Microsoft Fakes with OrganizationServiceContext through IOrganizationService" href="http://zhongchenzhou.wordpress.com/2012/08/02/part-6-microsoft-fakes-with-organizationservicecontext-through-iorganizationservice/" target="_blank">Part 6: Microsoft Fakes with OrganizationServiceContext through IOrganizationService</a></p>
<ul>
<li>Isolate method call to OrganizationServiceContext through mocking IOrganizationService</li>
</ul>
<p><a title="Part 7: Microsoft Fakes with CrmOrganizationServiceContext through IOrganizationService" href="http://zhongchenzhou.wordpress.com/2012/08/03/part-7-microsoft-fakes-with-crmorganizationservicecontext-through-iorganizationservice/" target="_blank">Part 7: Microsoft Fakes with CrmOrganizationServiceContext through IOrganizationService</a></p>
<ul>
<li>Isolate method call to OrganizationServiceContext extension methods through mocking IOrganizationService</li>
<li>Isolate method call to CrmOrganizationServiceContext through mocking IOrganizationService</li>
</ul>
<p><a title="Dynamics CRM 2011 Unit Test Part 8: Microsoft Fakes with IOrganizationService" href="http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-8-microsoft-fakes-with-iorganizationservice/" target="_blank">Part 8: Microsoft Fakes with IOrganizationService</a></p>
<ul>
<li>Using Stub type to isolate method call to IOrganizationService</li>
</ul>
<p><a title="Dynamics CRM 2011 Unit Test Part 9: Microsoft Fakes with CRM plugin" href="http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-9-microsoft-fakes-with-crm-plugin/" target="_blank">Part 9: Microsoft Fakes with CRM plugin</a></p>
<ul>
<li> Mock IOrganizationService, IPluginExecutionContext, ITracingService, IOrganizationServiceFactory and IServiceProvider</li>
</ul>
<p><a title="Dynamics CRM 2011 Unit Test Part 10: Microsoft Fakes with workflow activity" href="http://zhongchenzhou.wordpress.com/2012/08/03/dynamics-crm-2011-unit-test-part-10-microsoft-fakes-with-workflow-activity/" target="_blank">Part 10: Microsoft Fakes with workflow activity</a></p>
<ul>
<li>Correctly invoke CodeActivity.Execute(CodeActivityContext executionContext)</li>
<li>Correctly pass in InArgument&lt;T&gt; properties</li>
<li>Pass in required service as extensions</li>
</ul>
<p><a title="Dynamics CRM 2011 Unit Test Part 11: QUnit with client side JavaScript" href="http://zhongchenzhou.wordpress.com/2012/10/31/dynamics-crm-2011-unit-test-part-11-qunit-with-client-side-javascript/" target="_blank">Part 11: QUnit with client side JavaScript</a></p>
<ul>
<li>QUnit</li>
<li>Xrm.Page Script Library Template (Microsoft Visual Studio extension)</li>
</ul>
<p>Part 12: Rhino Mocks with LINQ query, OrganizationServiceContext and CrmOrganizationServiceContext</p>
<p>Part 13: Rhino Mocks with IOrganizationService</p>
<p><a title="Dynamics CRM 2011 Unit Test Part 14: Rhino Mocks with CRM plugin" href="http://zhongchenzhou.wordpress.com/2012/11/27/dynamics-crm-2011-unit-test-part-14-rhino-mocks-with-crm-plugin/" target="_blank">Part 14: Rhino Mocks with CRM plugin</a></p>
<p>Part 15: Rhino Mocks with workflow activity</p>
<p>Part 16: Moq with LINQ query, OrganizationServiceContext and CrmOrganizationServiceContext</p>
<p>Part 17: Moq with IOrganizationService</p>
<p>Part 18: Moq with CRM plugin</p>
<p>Part 19: Moq with workflow activity</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=463&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/07/08/dynamics-crm-2011-unit-test-part-1-introduction-and-series-contents/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 check previous value in preimage in workflow</title>
		<link>http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-check-previous-value-in-preimage-in-workflow/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-check-previous-value-in-preimage-in-workflow/#comments</comments>
		<pubDate>Fri, 29 Jun 2012 07:36:23 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=461</guid>
		<description><![CDATA[Sometimes it is required to check the previous value in a workflow triggered when record is updated. The out of the box workflow create user interface only provide access to current value of the record which is the value after &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-check-previous-value-in-preimage-in-workflow/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=461&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Sometimes it is required to check the previous value in a workflow triggered when record is updated.</p>
<p>The out of the box workflow create user interface only provide access to current value of the record which is the value after modification.</p>
<p>We could write one custom workflow activity to retrieve that value from IExecutionContext, which can be accessed from IWorkflowContext within custom workflow activity.</p>
<pre class="brush: csharp; title: ; notranslate">

protected override void Execute(CodeActivityContext executionContext)
 {
IWorkflowContext context = executionContext.GetExtension&lt;IWorkflowContext&gt;();
Entity preImageEntity = context.PreEntityImages.Values.FirstOrDefault();
}

</pre>
<p>When use InOutArgument&lt;EntityReference &gt; in custom workflow activity, we need to specify the entity name which made it difficult to reuse, instead we could accept the attribute name of the lookup field and output entity name and record id for that lookup field. We can use entity name and record id in other workflow activity to perform generic tasks.</p>
<p>Here is a sample code to retrieve record id and entity name from custom workflow activity</p>
<pre class="brush: csharp; title: ; notranslate">

public sealed class GetRecordIdEntityName : CodeActivity
 {
 [Input(&quot;Attribute Name for Related Record&quot;)]
 public InArgument&lt;String&gt; AttributeName { get; set; }

[Output(&quot;Primary Entity Name&quot;)]
 public OutArgument&lt;String&gt; PrimaryEntityName { get; set; }

[Output(&quot;Primary Record Id&quot;)]
 public OutArgument&lt;String&gt; PrimaryRecordId { get; set; }

[Output(&quot;Related Entity Name&quot;)]
 public OutArgument&lt;String&gt; RelatedEntityName { get; set; }

[Output(&quot;Pre Related Record Id&quot;)]
 public OutArgument&lt;String&gt; PreRelatedRecordId { get; set; }

[Output(&quot;Post Related Record Id&quot;)]
 public OutArgument&lt;String&gt; PostRelatedRecordId { get; set; }

/// &lt;summary&gt;
 /// Executes the workflow activity.
 /// &lt;/summary&gt;
 /// &lt;param name=&quot;executionContext&quot;&gt;The execution context.&lt;/param&gt;
 protected override void Execute(CodeActivityContext executionContext)
 {
 // Create the tracing service
 ITracingService tracingService = executionContext.GetExtension&lt;ITracingService&gt;();

if (tracingService == null)
 {
 throw new InvalidPluginExecutionException(&quot;Failed to retrieve tracing service.&quot;);
 }

tracingService.Trace(&quot;Entered GetRecordId.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}&quot;,
 executionContext.ActivityInstanceId,
 executionContext.WorkflowInstanceId);

// Create the context
 IWorkflowContext context = executionContext.GetExtension&lt;IWorkflowContext&gt;();

if (context == null)
 {
 throw new InvalidPluginExecutionException(&quot;Failed to retrieve workflow context.&quot;);
 }

tracingService.Trace(&quot;GetRecordId.Execute(), Correlation Id: {0}, Initiating User: {1}&quot;,
 context.CorrelationId,
 context.InitiatingUserId);

IOrganizationServiceFactory serviceFactory = executionContext.GetExtension&lt;IOrganizationServiceFactory&gt;();
 IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

try
 {
 // TODO: Implement your custom Workflow business logic.
 ExecuteCore(executionContext, context, service);
 }
 catch (FaultException&lt;OrganizationServiceFault&gt; e)
 {
 tracingService.Trace(&quot;Exception: {0}&quot;, e.ToString());

// Handle the exception.
 throw;
 }

tracingService.Trace(&quot;Exiting GetRecordId.Execute(), Correlation Id: {0}&quot;, context.CorrelationId);
 }

private void ExecuteCore(CodeActivityContext executionContext, IWorkflowContext context, IOrganizationService service)
 {
 this.PrimaryRecordId.Set(executionContext, context.PrimaryEntityId.ToString());

this.PrimaryEntityName.Set(executionContext, context.PrimaryEntityName.ToLowerInvariant());

string attributeName = this.AttributeName.Get(executionContext);

this.RelatedEntityName.Set(executionContext, null);

if (!string.IsNullOrWhiteSpace(attributeName))
 {
 Entity preImageEntity = context.PreEntityImages.Values.FirstOrDefault();
 if (preImageEntity != null &amp;&amp; preImageEntity.Contains(attributeName) &amp;&amp; preImageEntity[attributeName] is EntityReference)
 {
 EntityReference entityRef = preImageEntity.GetAttributeValue&lt;EntityReference&gt;(attributeName);
 this.RelatedEntityName.Set(executionContext, entityRef.LogicalName.ToLowerInvariant());
 this.PreRelatedRecordId.Set(executionContext, entityRef.Id.ToString());
 }
 else
 {
 this.PreRelatedRecordId.Set(executionContext, null);
 }

Entity postImageEntity = context.PostEntityImages.Values.FirstOrDefault();
 if (postImageEntity != null &amp;&amp; postImageEntity.Contains(attributeName) &amp;&amp; postImageEntity[attributeName] is EntityReference)
 {
 EntityReference entityRef = postImageEntity.GetAttributeValue&lt;EntityReference&gt;(attributeName);
 this.RelatedEntityName.Set(executionContext, entityRef.LogicalName.ToLowerInvariant());
 this.PostRelatedRecordId.Set(executionContext, entityRef.Id.ToString());
 }
 else
 {
 this.PostRelatedRecordId.Set(executionContext, null);
 }
 }
 else
 {
 this.PreRelatedRecordId.Set(executionContext, null);
 this.PostRelatedRecordId.Set(executionContext, null);
 }
 }
 }

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=461&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-check-previous-value-in-preimage-in-workflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 View to display records shared with current user</title>
		<link>http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-view-to-display-records-shared-with-current-user/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-view-to-display-records-shared-with-current-user/#comments</comments>
		<pubDate>Fri, 29 Jun 2012 01:58:09 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=457</guid>
		<description><![CDATA[In my current project, there is a requirement to create a view to display shared record of certain entity. This kind of view is supported but can not be achieved through customization user interface. System view and user view are &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-view-to-display-records-shared-with-current-user/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=457&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In my current project, there is a requirement to create a view to display shared record of certain entity.</p>
<p>This kind of view is supported but can not be achieved through customization user interface.</p>
<p>System view and user view are defined by using fetchxml and layoutxml, we could create a view through CRM API and set the correct fetchxml with is not support in out of the box customization user interface.</p>
<p>When records are shared, CRM create a record of &#8220;principalobjectaccess&#8221; entity; so we can link the entity we want to display to this entity to construct proper fetchxml.</p>
<p>The drawback of the approach is that you can not use customization user interface to modify the column layout and sort order.</p>
<p>Suppose we have an entity called &#8220;zzhou_cfiapplication&#8221; and we want to create a view to display records shared with current user.</p>
<p>The important piece of xml to add to view fetchxml is the link entity to &#8220;principalobjectaccesss&#8221; entity.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;link-entity name='principalobjectaccess' to='zzhou_cfiapplicationid' from='objectid' link-type='inner' alias='share'&gt;
 &lt;filter type='and'&gt;
 &lt;condition attribute='principalid' operator='eq-userid' /&gt;
 &lt;/filter&gt;
&lt;/link-entity&gt;

</pre>
<p>It is much more easier to configure the view in customization user interface to set up correct columns and sort order, and then modify the fetchxml for that view.</p>
<p>We can use the following code to retrieve the view that we want to modify</p>
<pre class="brush: csharp; title: ; notranslate">

public Entity RetrieveSavedQuery(OrganizationServiceContext context, Guid queryId)
 {
 var query = from q in context.CreateQuery(&quot;savedquery&quot;)
 where q.GetAttributeValue&lt;Guid&gt;(&quot;savedqueryid&quot;) == queryId
 select q;

Entity record = query.FirstOrDefault();

return record;
 }

</pre>
<p>we can update the view by using the following code</p>
<pre class="brush: csharp; title: ; notranslate">&lt;/pre&gt;
public void UpdateSavedQuery(IOrganizationService service)
 {
 Entity savedQuery = new Entity(&quot;savedquery&quot;);
 savedQuery.Id = new Guid(&quot;00bc926f-26c0-e111-a4f9-00155d4c5b01&quot;);
 savedQuery[&quot;fetchxml&quot;] = @&quot;&lt;fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'&gt;
 &lt;entity name='zzhou_cfiapplication'&gt;
 &lt;attribute name='zzhou_name' /&gt;
 &lt;attribute name='createdon' /&gt;
 &lt;order attribute='zzhou_name' descending='false' /&gt;
 &lt;link-entity name='principalobjectaccess' to='zzhou_cfiapplicationid' from='objectid' link-type='inner' alias='share'&gt;
 &lt;filter type='and'&gt;
 &lt;condition attribute='principalid' operator='eq-userid' /&gt;
 &lt;/filter&gt;
 &lt;/link-entity&gt;
 &lt;attribute name='zzhou_cfiapplicationid' /&gt;
 &lt;/entity&gt;
 &lt;/fetch&gt;&quot;;

service.Update(savedQuery);
 }
&lt;pre&gt;</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=457&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/06/29/dynamics-crm-2011-view-to-display-records-shared-with-current-user/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Share Secured Fields</title>
		<link>http://zhongchenzhou.wordpress.com/2012/06/28/dynamics-crm-2011-share-secured-fields/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/06/28/dynamics-crm-2011-share-secured-fields/#comments</comments>
		<pubDate>Thu, 28 Jun 2012 05:27:32 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=454</guid>
		<description><![CDATA[Dynamics CRM 2011 support field level security for custom attributes. Depending on your solution and security model for that solution, there might be a requirement to share secured fields in plugin, workflow or JavaScript. This post describe how to use &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/06/28/dynamics-crm-2011-share-secured-fields/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=454&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Dynamics CRM 2011 support field level security for custom attributes. Depending on your solution and security model for that solution, there might be a requirement to share secured fields in plugin, workflow or JavaScript.</p>
<p>This post describe how to use late bound entities to create a custom workflow activity to share secured fields, the complete code is in the end of this post.</p>
<p><strong> Note:</strong> If users&#8217; security role says they cannot update records, then they will not be able to update any field on that <strong>record</strong> even if there is a field level security profile says that they can update that field on that <strong>entity</strong>.</p>
<p>Each time when users share a secured field to other users, CRM create records of entity &#8220;principalobjectattributeaccess&#8221; with proper value set for &#8221;readaccess&#8221;, &#8220;updateaccess&#8221;, &#8221;attributeid&#8221;,&#8221;objectid&#8221;, and &#8221;principalid&#8221; attributes.</p>
<p>To create this entity correctly, we need the id of the attribute metadata, so we can use the following code to retrieve that id based on the attribute name</p>
<pre class="brush: csharp; title: ; notranslate">

// Create the request
 RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
 {
 EntityLogicalName = entityName,
 LogicalName = attributeName,
 RetrieveAsIfPublished = true
 };

// Execute the request
 RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)service.Execute(attributeRequest);

</pre>
<p>CRM does not allow duplicate records for &#8221;principalobjectattributeaccess&#8221; entity, so we need to uses some query like below to check whether there is record exists first.</p>
<pre class="brush: csharp; title: ; notranslate">

// Create the query for retrieve User Shared Attribute permissions.
 QueryExpression queryPOAA = new QueryExpression(&quot;principalobjectattributeaccess&quot;);
 queryPOAA.ColumnSet = new ColumnSet(new string[] { &quot;readaccess&quot;, &quot;updateaccess&quot; });
 queryPOAA.Criteria.FilterOperator = LogicalOperator.And;
 queryPOAA.Criteria.Conditions.Add(new ConditionExpression(&quot;attributeid&quot;, ConditionOperator.Equal, metadataId));
 queryPOAA.Criteria.Conditions.Add(new ConditionExpression(&quot;objectid&quot;, ConditionOperator.Equal, objectId));
 queryPOAA.Criteria.Conditions.Add(new ConditionExpression(&quot;principalid&quot;, ConditionOperator.Equal, principalId));

// Execute the query.
 EntityCollection responsePOAA = service.RetrieveMultiple(queryPOAA);

</pre>
<p>We can now create or update the record to share and update secured field.</p>
<p>Here is the complete custom workflow activity</p>
<pre class="brush: csharp; title: ; notranslate">

// &lt;copyright file=&quot;ShareSecuredField.cs&quot; company=&quot;&quot;&gt;
// Copyright (c) 2012 All Rights Reserved
// &lt;/copyright&gt;
// &lt;author&gt;&lt;/author&gt;
// &lt;date&gt;6/5/2012 11:41:45 PM&lt;/date&gt;
// &lt;summary&gt;Implements the ShareSecuredField Workflow Activity.&lt;/summary&gt;
namespace Xrm.Workflow.Activities
{
 using System;
 using System.Activities;
 using System.ServiceModel;
 using Microsoft.Xrm.Sdk;
 using Microsoft.Xrm.Sdk.Workflow;
 using Microsoft.Xrm.Sdk.Messages;
 using Microsoft.Xrm.Sdk.Query;

public sealed class ShareSecuredField : CodeActivity
 {
 [RequiredArgument]
 [Input(&quot;Attribute Name&quot;)]
 public InArgument&lt;String&gt; AttributeName { get; set; }

[Input(&quot;Share With User&quot;)]
 [ReferenceTarget(&quot;systemuser&quot;)]
 public InArgument&lt;EntityReference&gt; UserToShare { get; set; }

[Input(&quot;Share With Team&quot;)]
 [ReferenceTarget(&quot;team&quot;)]
 public InArgument&lt;EntityReference&gt; TeamToShare { get; set; }

[RequiredArgument]
 [Input(&quot;Allow Read&quot;)]
 [Default(&quot;true&quot;)]
 public InArgument&lt;Boolean&gt; AllowRead { get; set; }

[RequiredArgument]
 [Input(&quot;Allow Update&quot;)]
 [Default(&quot;true&quot;)]
 public InArgument&lt;Boolean&gt; AllowUpdate { get; set; }

/// &lt;summary&gt;
 /// Executes the workflow activity.
 /// &lt;/summary&gt;
 /// &lt;param name=&quot;executionContext&quot;&gt;The execution context.&lt;/param&gt;
 protected override void Execute(CodeActivityContext executionContext)
 {
 // Create the tracing service
 ITracingService tracingService = executionContext.GetExtension&lt;ITracingService&gt;();

if (tracingService == null)
 {
 throw new InvalidPluginExecutionException(&quot;Failed to retrieve tracing service.&quot;);
 }

tracingService.Trace(&quot;Entered ShareSecuredField.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}&quot;, executionContext.ActivityInstanceId, executionContext.WorkflowInstanceId);

// Create the context
 IWorkflowContext context = executionContext.GetExtension&lt;IWorkflowContext&gt;();

if (context == null)
 {
 throw new InvalidPluginExecutionException(&quot;Failed to retrieve workflow context.&quot;);
 }

tracingService.Trace(&quot;ShareSecuredField.Execute(), Correlation Id: {0}, Initiating User: {1}&quot;, context.CorrelationId, context.InitiatingUserId);

IOrganizationServiceFactory serviceFactory = executionContext.GetExtension&lt;IOrganizationServiceFactory&gt;();
 IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

try
 {
 // TODO: Implement your custom Workflow business logic.
 ExecuteCore(executionContext, context, service);
 }
 catch (FaultException&lt;OrganizationServiceFault&gt; e)
 {
 tracingService.Trace(&quot;Exception: {0}&quot;, e.ToString());

// Handle the exception.
 throw;
 }

tracingService.Trace(&quot;Exiting ShareSecuredField.Execute(), Correlation Id: {0}&quot;, context.CorrelationId);
 }

private void ExecuteCore(CodeActivityContext executionContext, IWorkflowContext context, IOrganizationService service)
 {
 string entityName = context.PrimaryEntityName;
 Guid entityId = context.PrimaryEntityId;
 string attributeName = this.AttributeName.Get(executionContext);
 EntityReference userToShare = this.UserToShare.Get(executionContext);
 EntityReference teamToShare = this.TeamToShare.Get(executionContext);
 bool allowRead = this.AllowRead.Get(executionContext);
 bool allowUpdate = this.AllowUpdate.Get(executionContext);

if (userToShare != null)
 {
 Guid objectId = userToShare.Id;
 ShareSecuredFieldCore(service, entityName, attributeName, entityId, objectId, allowRead, allowUpdate, false);
 }

if (teamToShare != null)
 {
 Guid objectId = teamToShare.Id;
 ShareSecuredFieldCore(service, entityName, attributeName, entityId, objectId, allowRead, allowUpdate);
 }
 }

private void ShareSecuredFieldCore(IOrganizationService service, string entityName, string attributeName, Guid objectId, Guid principalId, bool allowRead, bool allowUpdate, bool shareWithTeam = true)
 {
 // Create the request
 RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
 {
 EntityLogicalName = entityName,
 LogicalName = attributeName,
 RetrieveAsIfPublished = true
 };

// Execute the request
 RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)service.Execute(attributeRequest);

if (attributeResponse.AttributeMetadata != null &amp;&amp; attributeResponse.AttributeMetadata.IsSecured != null &amp;&amp; attributeResponse.AttributeMetadata.IsSecured.HasValue &amp;&amp; attributeResponse.AttributeMetadata.IsSecured.Value)
 {
 // Create the query for retrieve User Shared Attribute permissions.
 QueryExpression queryPOAA = new QueryExpression(&quot;principalobjectattributeaccess&quot;);
 queryPOAA.ColumnSet = new ColumnSet(new string[] { &quot;readaccess&quot;, &quot;updateaccess&quot; });
 queryPOAA.Criteria.FilterOperator = LogicalOperator.And;
 queryPOAA.Criteria.Conditions.Add(new ConditionExpression(&quot;attributeid&quot;, ConditionOperator.Equal, attributeResponse.AttributeMetadata.MetadataId));
 queryPOAA.Criteria.Conditions.Add(new ConditionExpression(&quot;objectid&quot;, ConditionOperator.Equal, objectId));
 queryPOAA.Criteria.Conditions.Add(new ConditionExpression(&quot;principalid&quot;, ConditionOperator.Equal, principalId));

// Execute the query.
 EntityCollection responsePOAA = service.RetrieveMultiple(queryPOAA);

if (responsePOAA.Entities.Count &gt; 0)
 {
 Entity poaa = responsePOAA.Entities[0];

if (allowRead || allowUpdate)
 {
 poaa[&quot;readaccess&quot;] = allowRead;
 poaa[&quot;updateaccess&quot;] = allowUpdate;

service.Update(poaa);
 }
 else
 {
 service.Delete(&quot;principalobjectattributeaccess&quot;, poaa.Id);
 }
 }
 else
 {
 if (allowRead || allowUpdate)
 {
 // Create POAA entity for user
 Entity poaa = new Entity(&quot;principalobjectattributeaccess&quot;);
 poaa[&quot;attributeid&quot;] = attributeResponse.AttributeMetadata.MetadataId;
 poaa[&quot;objectid&quot;] = new EntityReference(entityName, objectId);
 poaa[&quot;readaccess&quot;] = allowRead;
 poaa[&quot;updateaccess&quot;] = allowUpdate;
 if (shareWithTeam)
 {
 poaa[&quot;principalid&quot;] = new EntityReference(&quot;team&quot;, principalId);
 }
 else
 {
 poaa[&quot;principalid&quot;] = new EntityReference(&quot;systemuser&quot;, principalId);
 }

service.Create(poaa);
 }
 }
 }
 }
 }
}

</pre>
<p>There are sample code in the following location in the SDK download:</p>
<p>SampleCode\CS\FieldSecurity\RetrieveUserSharedAttributePermissions.cs</p>
<p>SampleCode\VB\FieldSecurity\RetrieveUserSharedAttributePermissions.vb</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=454&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/06/28/dynamics-crm-2011-share-secured-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint</title>
		<link>http://zhongchenzhou.wordpress.com/2012/05/20/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/05/20/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint/#comments</comments>
		<pubDate>Sun, 20 May 2012 12:57:51 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Kendo UI]]></category>
		<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=448</guid>
		<description><![CDATA[Update: the updated post with new sample code can be found here: How to use Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint Sample 1 The complete source code can be download from sample gallery: Kendo UI DataSource, &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/05/20/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=448&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong>Update: the updated post with new sample code can be found here: <a title="How to use Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint Sample 1" href="http://zhongchenzhou.wordpress.com/2012/09/23/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint-sample-1/" target="_blank">How to use Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint Sample 1</a></strong></p>
<p>The complete source code can be download from sample gallery: <a title="Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint" href="http://code.msdn.microsoft.com/Kendo-UI-DataSource-Kendo-33a3dc77" target="_blank">Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint</a></p>
<p><a title="Kendo UI" href="http://www.kendoui.com/" target="_blank">Kendo UI</a> is a HTML5, jQuery-based framework for building modern HTML apps. Kendo UI combines the best of emerging HTML5, CSS3, and JavaScript technologies with robust, cross-browser techniques to deliver a framework that is both powerfully rich and broadly compatible with older browsers.</p>
<p><a title="MS Dynamic CRM R8 CTP Beta" href="https://connect.microsoft.com/site68\/Downloads" target="_blank">Microsoft Dynamics CRM 2011 Release 8</a> include support for IE, Chrome, Firefox and Safari.</p>
<p>By using a powerful JavaScript framework, the use of ASP.NET is reduced which would remove the complexity of deployment which also makes the solution much more portable.</p>
<p>By using Kendo UI DataSource, Kendo UI Grid with Dynamics CRM 2011 REST Endpoint, it is easy to implement server side filter, sorting and paging.</p>
<p>There are a few tricks to use Kendo UI together with Dynamics CRM 2011 I want to share. The complete code is in the end of this post.</p>
<p>1. Microsoft Dynamics CRM 2011 REST Endpoint does <strong>not</strong> support <strong>$format</strong> system query option.</p>
<p>You can use a global jQuery ajax event handler to specifying http header ensures that the results will be returned as JSON.</p>
<pre class="brush: jscript; title: ; notranslate">

$(document).ajaxSend(function (e, jqxhr, settings) {
 if (settings.url.toLowerCase().indexOf(&quot;XRMServices/2011/OrganizationData.svc&quot;.toLowerCase()) &gt;= 0) {
 jqxhr.setRequestHeader(&quot;Accept&quot;, &quot;application/json&quot;);
 }
});

</pre>
<p>2. Microsoft Dynamics CRM 2011 REST Endpoint does <strong>not</strong> support <strong>$inlinecount, $count</strong> system query option.</p>
<p>you can set a function to use fetch xml and soap endpoint to return the total record count.</p>
<pre class="brush: jscript; title: ; notranslate">

var dataSource = new kendo.data.DataSource({
 schema: {
 total: function (data) {

var fetchXml = '' +
 '' +
 &quot;&quot; +
 '' +
 '';

var context = GetGlobalContext();

var serverUrl = window.parent.document.location.protocol + '//' + window.parent.document.location.host + '/' + context.getOrgUniqueName();

var _oService = new FetchUtil(context.getOrgUniqueName(), serverUrl);
 var res = _oService.Fetch(fetchXml);

var count = res[0].attributes.count.formattedValue;

return count;
 }
 }
});

</pre>
<p>3. you need to stop Kendo UI to send default query string parameter and use Dynamics CRM 2011 specific format</p>
<pre class="brush: jscript; title: ; notranslate">

var dataSource = new kendo.data.DataSource({
 transport: {
 parameterMap: function (options) {
 return {
 $top: options.take,
 $skip: options.skip,
 $select: 'cgi_name,cgi_postcodeareaId',
 $orderby: options.sort[0].field + ' ' + options.sort[0].dir
 };
 }
 }
});

</pre>
<p>4. you have to parse returned json object to return object array that Kendo UI understand</p>
<pre class="brush: jscript; title: ; notranslate">

var dataSource = new kendo.data.DataSource({
 schema: {
 parse: function (data) {
 return data.d.results;
 },
 type: &quot;json&quot;
 }
});

</pre>
<p><strong>Complete Kendo UI DataSource code</strong></p>
<pre class="brush: jscript; title: ; notranslate">
var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: &quot;http://vmcrm/RECRegistry/XRMServices/2011/OrganizationData.svc/cgi_postcodeareaSet&quot;,
            dataType: 'json'
        },
        parameterMap: function (options) {
            return {
                $top: options.take,
                $skip: options.skip,
                $select: 'cgi_name,cgi_postcodeareaId',
                $orderby: options.sort[0].field + ' ' + options.sort[0].dir
            };
        }
    },
    schema: {
        model: {
            id: &quot;cgi_postcodeareaId&quot;,
            fields: {
                cgi_name: { type: &quot;string&quot; },
                cgi_postcodeareaId: { type: &quot;string&quot; }
            }
        },
        total: function (data) {

            var fetchXml = '' +
                                           '' +
                                                &quot;&quot; +
                                           '' +
                                       '';

            var context = GetGlobalContext();

            var serverUrl = window.parent.document.location.protocol + '//' + window.parent.document.location.host + '/' + context.getOrgUniqueName();

            var _oService = new FetchUtil(context.getOrgUniqueName(), serverUrl);
            var res = _oService.Fetch(fetchXml);

            var count = res[0].attributes.count.formattedValue;

            return count;
        },
        parse: function (data) {
            return data.d.results;
        },
        type: &quot;json&quot;
    },
    serverPaging: true,
    pageSize: 10,
    serverSorting: true,
    sort: { field: &quot;cgi_name&quot;, dir: &quot;asc&quot; }
});
</pre>
<p><strong>Complete Sample code</strong></p>
<pre class="brush: jscript; title: ; notranslate">

    Postcode Areas
&lt;script type=&quot;text/javascript&quot; src=&quot;../Scripts/jquery.min.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;../Scripts/kendo.web.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;../Scripts/FetchUtil.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;../../../ClientGlobalContext.js.aspx&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
        var selectedIds = {};

        $(document).ready(function ($) {

            var dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: &quot;http://vmcrm/RECRegistry/XRMServices/2011/OrganizationData.svc/cgi_postcodeareaSet&quot;,
                        dataType: 'json'
                    },
                    parameterMap: function (options) {
                        return {
                            $top: options.take,
                            $skip: options.skip,
                            $select: 'cgi_name,cgi_postcodeareaId',
                            $orderby: options.sort[0].field + ' ' + options.sort[0].dir
                        };
                    }
                },
                schema: {
                    model: {
                        id: &quot;cgi_postcodeareaId&quot;,
                        fields: {
                            cgi_name: { type: &quot;string&quot; },
                            cgi_postcodeareaId: { type: &quot;string&quot; }
                        }
                    },
                    total: function (data) {

                        var fetchXml = '&lt;fetch mapping=&quot;logical&quot; aggregate=&quot;true&quot;&gt;' +
                                           '&lt;entity name=&quot;cgi_postcodearea&quot;&gt;' +
                                                &quot;&lt;attribute name='cgi_postcodeareaid' alias='count' aggregate='count'/&gt;&quot; +
                                           '&lt;/entity&gt;' +
                                       '&lt;/fetch&gt;';

                        var context = GetGlobalContext();

                        var serverUrl = window.parent.document.location.protocol + '//' + window.parent.document.location.host + '/' + context.getOrgUniqueName();

                        var _oService = new FetchUtil(context.getOrgUniqueName(), serverUrl);
                        var res = _oService.Fetch(fetchXml);

                        var count = res[0].attributes.count.formattedValue;

                        return count;
                    },
                    parse: function (data) {
                        return data.d.results;
                    },
                    type: &quot;json&quot;
                },
                serverPaging: true,
                pageSize: 10,
                serverSorting: true,
                sort: { field: &quot;cgi_name&quot;, dir: &quot;asc&quot; }
            });

            var ctlGrid = $(&quot;#PostcodeAreaKendoGrid&quot;);

            ctlGrid.kendoGrid({
                dataSource: dataSource,
                columns: [{
                    template: '&lt;input type=&quot;checkbox&quot; /&gt;',
                    sortable: false,
                    width: 9
                },
                {
                    title: 'Postcode Area',
                    field: &quot;cgi_name&quot;,
                    width: 120
                }],
                editable: false,
                pageable: true,
                selectable: &quot;multiple, row&quot;,
                sortable: {
                    mode: 'single',
                    allowUnsort: false
                },
                dataBound: function () {
                    var grid = this;
                    //handle checkbox change
                    grid.table.find(&quot;tr&quot;).find(&quot;td:first input&quot;)
                        .change(function (e) {
                            var checkbox = $(this);
                            var selected = grid.table.find(&quot;tr&quot;).find(&quot;td:first input:checked&quot;).closest(&quot;tr&quot;);

                            grid.clearSelection();

                            //persist selection per page
                            var ids = selectedIds[grid.dataSource.page()] = [];

                            if (selected.length) {
                                grid.select(selected);
                                selected.each(function (idx, item) {
                                    ids.push(grid.dataItem(item).id);
                                });
                            }

                        })
                        .end()
                        .mousedown(function (e) {
                            e.stopPropagation();
                        });

                    //select persisted rows
                    var selected = $();
                    var ids = selectedIds[grid.dataSource.page()] || [];

                    for (var idx = 0, length = ids.length; idx &lt; length; idx++) {
                        var dataItem = grid.dataSource.get(ids[idx]);
                        if (dataItem) {
                            selected = selected.add(grid.table.find(&quot;tr[data-uid=&quot; + dataItem.uid + &quot;]&quot;));
                        }
                    }

                    selected
                        .find(&quot;td:first input&quot;)
                        .attr(&quot;checked&quot;, true)
                        .trigger(&quot;change&quot;);

                }
            });

            var grid = ctlGrid.data(&quot;kendoGrid&quot;);

            grid.thead.find(&quot;th:first&quot;)
                .append($('&lt;input class=&quot;selectAll&quot; type=&quot;checkbox&quot;/&gt;'))
                .delegate(&quot;.selectAll&quot;, &quot;click&quot;, function () {
                    var checkbox = $(this);

                    grid.table.find(&quot;tr&quot;)
                        .find(&quot;td:first input&quot;)
                        .attr(&quot;checked&quot;, checkbox.is(&quot;:checked&quot;))
                        .trigger(&quot;change&quot;);
                });
        }).ajaxSend(function (e, jqxhr, settings) {
            if (settings.url.toLowerCase().indexOf(&quot;XRMServices/2011/OrganizationData.svc&quot;.toLowerCase()) &gt;= 0) {
                jqxhr.setRequestHeader(&quot;Accept&quot;, &quot;application/json&quot;);
            }
        });

// ]]&gt;&lt;/script&gt;&lt;/pre&gt;
&lt;div id=&quot;PostcodeAreaKendoGrid&quot;&gt;&lt;/div&gt;
&lt;pre&gt;

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/kendo-ui/'>Kendo UI</a>, <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/kendo-ui/'>Kendo UI</a>, <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=448&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/05/20/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Create plug-in for message with no primary entity associated using Dynamics CRM 2011 developer toolkit</title>
		<link>http://zhongchenzhou.wordpress.com/2012/05/20/create-plug-in-for-message-with-no-primary-entity-associated-using-dynamics-crm-2011-developer-toolkit/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/05/20/create-plug-in-for-message-with-no-primary-entity-associated-using-dynamics-crm-2011-developer-toolkit/#comments</comments>
		<pubDate>Sun, 20 May 2012 11:42:19 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=442</guid>
		<description><![CDATA[Dynamics CRM 2011 developer toolkit is a visual studio extension included in SDK which accelerate creation and deployment of plug-ins, custom workflow assemblies, XAML workflows and Web resources. For more information about Dynamics CRM 2011 developer toolkit: Developer Toolkit for Microsoft Dynamics &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/05/20/create-plug-in-for-message-with-no-primary-entity-associated-using-dynamics-crm-2011-developer-toolkit/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=442&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Dynamics CRM 2011 developer toolkit is a visual studio extension included in SDK which accelerate creation and deployment of plug-ins, custom workflow assemblies, XAML workflows and Web resources. For more information about Dynamics CRM 2011 developer toolkit: <a title="Developer Toolkit for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online" href="http://msdn.microsoft.com/en-us/library/hh372957" target="_blank">Developer Toolkit for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online</a>.</p>
<p>When create plug-in using developer toolkit, you need to first select the primary entity for the message. There are 19 messages with no primary entity associated, which are listed below.</p>
<table width="239" border="0" cellspacing="0" cellpadding="0">
<col width="239" />
<tbody>
<tr>
<td width="239" height="20">Associate</td>
</tr>
<tr>
<td height="20">Disassociate</td>
</tr>
<tr>
<td height="20">Execute</td>
</tr>
<tr>
<td height="20">Export</td>
</tr>
<tr>
<td height="20">ExportAll</td>
</tr>
<tr>
<td height="20">ExportCompressed</td>
</tr>
<tr>
<td height="20">ExportCompressedAll</td>
</tr>
<tr>
<td height="20">Import</td>
</tr>
<tr>
<td height="20">ImportAll</td>
</tr>
<tr>
<td height="20">ImportCompressedAll</td>
</tr>
<tr>
<td height="20">ImportCompressedWithProgress</td>
</tr>
<tr>
<td height="20">ImportWithProgress</td>
</tr>
<tr>
<td height="20">Publish</td>
</tr>
<tr>
<td height="20">PublishAll</td>
</tr>
<tr>
<td height="20">RemoveProductFromKit</td>
</tr>
<tr>
<td height="20">RetrievePersonalWall</td>
</tr>
<tr>
<td height="20">RetrieveRecordWall</td>
</tr>
<tr>
<td height="20">UnlockInvoicePricing</td>
</tr>
<tr>
<td height="20">UnlockSalesOrderPricing</td>
</tr>
</tbody>
</table>
<p>To create plug-in using developer toolkit for message with no primary entity associated, you can create a plug-in as normal process and modify the generated .cs code file and the RegisterFile.crmregister file.</p>
<p>1. select <strong>any</strong> entity and create plug-in in CRM Explorer</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/toolkit-1.png"><img class="alignnone size-medium wp-image-443" title="toolkit 1" src="http://zhongchenzhou.files.wordpress.com/2012/05/toolkit-1.png?w=170&#038;h=300" alt="" width="170" height="300" /></a></p>
<p>2. select <strong>any</strong> message to use, and configure other setting as you need for the message have no primary entity.</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/toolkit-2.png"><img class="alignnone size-medium wp-image-444" title="toolkit 2" src="http://zhongchenzhou.files.wordpress.com/2012/05/toolkit-2.png?w=300&#038;h=205" alt="" width="300" height="205" /></a></p>
<p>3. modify generated .cs code file, so that the plug-in will be executed</p>
<p>the line number is likely to be line 31, on the top of the generated plug-in .cs code file within the plug-in constructor.</p>
<p>update the message to the one have no primary entity and change the entity name to empty string</p>
<pre class="brush: csharp; title: ; notranslate">base.RegisteredEvents.Add(new Tuple&lt;int, string, string, Action&lt;LocalPluginContext&gt;&gt;(10, &quot;Associate&quot;, &quot;&quot;, new Action&lt;LocalPluginContext&gt;(ExecutePreValidatePostcodeAssociate)));</pre>
<p>4. modify RegisterFile.crmregister file, so that the plug-in can be deployed to the CRM server correctly</p>
<p>find the xml for previously generated plug-in, update the message and change entity name to empty string</p>
<pre class="brush: xml; title: ; notranslate">&lt;Step CustomConfiguration=&quot;&quot; Name=&quot;PreValidatePostcodeAssociate&quot; Description=&quot;Pre-Validation of Postcode Associate&quot; Id=&quot;881876af-8ba0-e111-b344-00155d4c5b01&quot; MessageName=&quot;Associate&quot; Mode=&quot;Synchronous&quot; PrimaryEntityName=&quot;&quot; Rank=&quot;1&quot; SecureConfiguration=&quot;&quot; Stage=&quot;PreOutsideTransaction&quot; SupportedDeployment=&quot;Both&quot;</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=442&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/05/20/create-plug-in-for-message-with-no-primary-entity-associated-using-dynamics-crm-2011-developer-toolkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/toolkit-1.png?w=170" medium="image">
			<media:title type="html">toolkit 1</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/toolkit-2.png?w=300" medium="image">
			<media:title type="html">toolkit 2</media:title>
		</media:content>
	</item>
		<item>
		<title>useful query for identifying performance problems within SQL Server</title>
		<link>http://zhongchenzhou.wordpress.com/2012/05/19/useful-query-for-identifying-performance-problems-within-sql-server/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/05/19/useful-query-for-identifying-performance-problems-within-sql-server/#comments</comments>
		<pubDate>Sat, 19 May 2012 02:38:06 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=440</guid>
		<description><![CDATA[Filed under: SQL Server Tagged: SQL Server<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=440&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: sql; title: ; notranslate">

SELECT
@@SERVERNAME as ServerName,
a.session_id,
datediff(ss, a.Start_Time, getdate()) as seconds,
a.wait_type,
a.wait_time,
m.requested_memory_kb / 1024 as requestedMB,
a.granted_query_memory,
m.dop,
a.command,
d.Name as DBName,
a.blocking_session_id as blockedby,
LTRIM(b.text) as sproc,
substring(b.text, a.statement_start_offset / 2,
CASE WHEN
(a.statement_end_offset - a.statement_start_offset) / 2 &gt; 0
THEN
(a.statement_end_offset - a.statement_start_offset) / 2
ELSE 1
END) as stmt,
a.last_wait_type,
a.wait_resource,
a.reads,
a.writes,
a.logical_reads,
a.cpu_time
FROM
sys.dm_exec_requests a with (NOLOCK)
OUTER APPLY sys.dm_exec_sql_text(a.sql_handle) b
LEFT JOIN
sys.dm_exec_query_memory_grants m (NOLOCK)
on m.session_id = a.session_id
and m.request_id = a.request_id
LEFT JOIN
sys.databases d
ON d.database_id = a.database_id
WHERE
a.session_id &gt; 50
AND a.session_id &lt; &gt; @@spid
ORDER BY
datediff(ss, a.Start_Time, getdate()) DESC

</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/sql-server/'>SQL Server</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/sql-server/'>SQL Server</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=440&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/05/19/useful-query-for-identifying-performance-problems-within-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM Remote Debugging step by step</title>
		<link>http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-remote-debugging-step-by-step/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-remote-debugging-step-by-step/#comments</comments>
		<pubDate>Thu, 17 May 2012 01:58:18 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=433</guid>
		<description><![CDATA[1. Register and deploy the plug-in assembly. 2. Copy compiled plug-in assembly&#8217;s symbol file (.pdb) to the server&#8217;s &#60;crm-root&#62;\Server\bin\assembly folder and restart Internet Information Services (IIS) 3. If the plugin is a Sandboxed Plug-in, set the following registry key to 1 (DWORD) (Create one if &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-remote-debugging-step-by-step/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=433&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>1. Register and deploy the plug-in assembly.</p>
<p>2. Copy compiled plug-in assembly&#8217;s symbol file (.pdb) to the server&#8217;s &lt;crm-root&gt;\Server\bin\assembly folder and restart Internet Information Services (IIS)</p>
<p>3. If the plugin is a Sandboxed Plug-in, set the following registry key to 1 (<strong>DWORD</strong>) (Create one if it does not exist); restart &#8220;<strong>Microsoft Dynamics CRM Sandbox Processing Service</strong>&#8220; on the sandbox server</p>
<pre class="brush: plain; title: ; notranslate">
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM\SandboxDebugPlugins
</pre>
<p>&nbsp;</p>
<p>4. Copy Remote Debugger (copy entire folder) from local visual studio install folder to remote server, it is located in</p>
<pre class="brush: plain; title: ; notranslate">
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger\x64
</pre>
<p>5. Run msvsmon.exe you copied from previous step on remote server</p>
<p>6. Configure firewall for remote debugging on remote server</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-1.png"><img class="alignnone size-medium wp-image-434" title="remote debug 1" src="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-1.png?w=300&#038;h=117" alt="" width="300" height="117" /></a></p>
<p>7. Copy remote debugger server name from Tools -&gt; Options -&gt; Server Name</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-2.png"><img class="alignnone size-medium wp-image-435" title="remote debug 2" src="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-2.png?w=300&#038;h=99" alt="" width="300" height="99" /></a></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-3.png"><img class="alignnone size-medium wp-image-436" title="remote debug 3" src="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-3.png?w=300&#038;h=217" alt="" width="300" height="217" /></a></p>
<p>8. Attach to process from local visual studio -&gt; Debug -&gt; Attach to process&#8230;</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-4.png"><img class="alignnone size-medium wp-image-437" title="remote debug 4" src="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-4.png?w=300&#038;h=257" alt="" width="300" height="257" /></a></p>
<p>9. Set Transport to Default, set Qualifier to the value copies from step 7, (it might looks similar to this: Domain\Account@CRMServerName), select &#8220;Show processes from all users&#8221;</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-5.png"><img class="alignnone size-medium wp-image-438" title="remote debug 5" src="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-5.png?w=300&#038;h=203" alt="" width="300" height="203" /></a></p>
<p>10. select the right process to attach depend on plug in</p>
<ul>
<li><strong>online</strong>: w3wp.exe</li>
<li><strong>offline</strong>: Microsoft.Crm.Application.Hoster.exe</li>
<li><strong>asynchronous registered plug-ins (or custom workflow assemblies)</strong>: CrmAsyncService.exe</li>
<li><strong>sandbox (isolation mode)</strong>: Microsoft.Crm.Sandbox.WorkerProcess.exe</li>
</ul>
<p>11. set one or more breakpoints in your plug-in code</p>
<p>12. trigger plugin to run</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=433&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-remote-debugging-step-by-step/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-1.png?w=300" medium="image">
			<media:title type="html">remote debug 1</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-2.png?w=300" medium="image">
			<media:title type="html">remote debug 2</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-3.png?w=300" medium="image">
			<media:title type="html">remote debug 3</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-4.png?w=300" medium="image">
			<media:title type="html">remote debug 4</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/remote-debug-5.png?w=300" medium="image">
			<media:title type="html">remote debug 5</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 plugin error: &#8220;You do not have the necessary permission to change the domain logon name for this user&#8221; Access is denied. System.UnauthorizedAccessException</title>
		<link>http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-2011-plugin-error-you-do-not-have-the-necessary-permission-to-change-the-domain-logon-name-for-this-user-access-is-denied-system-unauthorizedaccessexception/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-2011-plugin-error-you-do-not-have-the-necessary-permission-to-change-the-domain-logon-name-for-this-user-access-is-denied-system-unauthorizedaccessexception/#comments</comments>
		<pubDate>Thu, 17 May 2012 01:09:02 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=429</guid>
		<description><![CDATA[You might come across this error within plugin &#8221;You do not have the necessary permission to change the domain logon name for this user&#8221; Access is denied. The system job details might looks like this If the plugin is synchronous, add &#8220;CRMAppPool&#8221; Identity account &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-2011-plugin-error-you-do-not-have-the-necessary-permission-to-change-the-domain-logon-name-for-this-user-access-is-denied-system-unauthorizedaccessexception/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=429&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>You might come across this error within plugin &#8221;You do not have the necessary permission to change the domain logon name for this user&#8221; Access is denied.</p>
<p>The system job details might looks like this</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/05/access-denied.png"><img class="alignnone size-medium wp-image-430" title="access denied" src="http://zhongchenzhou.files.wordpress.com/2012/05/access-denied.png?w=300&#038;h=256" alt="" width="300" height="256" /></a></p>
<p>If the plugin is synchronous, add &#8220;<strong>CRMAppPool</strong>&#8221; Identity account to &#8220;<strong>Local Administrators Group</strong>&#8220;, restart IIS.</p>
<p>If the plugin is asynchronous, add &#8220;<strong>Microsoft Dynamics CRM Asynchronous Processing Service</strong>&#8221; logon account to &#8220;<strong>Local Administrators Group</strong>&#8220;, restart service.</p>
<p>&nbsp;</p>
<p>This might also happen when you use user account to run &#8220;<strong>CRMAppPool</strong>&#8221; and &#8220;<strong>Microsoft Dynamics CRM Asynchronous Processing Service</strong>&#8221; and the password is changed, in that case check the if the password is correct and update the password if necessary.</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=429&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/05/17/dynamics-crm-2011-plugin-error-you-do-not-have-the-necessary-permission-to-change-the-domain-logon-name-for-this-user-access-is-denied-system-unauthorizedaccessexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/05/access-denied.png?w=300" medium="image">
			<media:title type="html">access denied</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development – CrmHyperLink</title>
		<link>http://zhongchenzhou.wordpress.com/2012/05/07/dynamics-crm-2011-portal-development-crmhyperlink/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/05/07/dynamics-crm-2011-portal-development-crmhyperlink/#comments</comments>
		<pubDate>Mon, 07 May 2012 02:12:43 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=423</guid>
		<description><![CDATA[. Dynamics CRM 2011 Portal Development Use the CrmHyperLink control to create a link to another Web page within your CRM portal. The &#8220;URL&#8221; is consists of &#8221;partial url property&#8221; of &#8220;Web Page entity&#8221;. The CrmHyperLink control is typically displayed as &#8220;text&#8221; specified &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/05/07/dynamics-crm-2011-portal-development-crmhyperlink/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=423&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>.<br />
<a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p>Use the CrmHyperLink control to create a link to another Web page within your CRM portal. The &#8220;<strong>URL&#8221;</strong> is consists of<strong> &#8221;partial url property&#8221; of &#8220;Web Page entity&#8221;</strong>. The CrmHyperLink control is typically displayed as &#8220;<strong>text&#8221;</strong> specified by the &#8220;<strong>name&#8221; property of &#8220;Web Page&#8221; entity</strong>.</p>
<p>Microsoft.Xrm.Portal.Web.UI.WebControls.<strong>CrmHyperLink</strong> inherent from System.Web.UI.WebControls.<strong>HyperLink</strong> and expose three extra properties; PortalName, SiteMarkerName and QueryString.</p>
<p><strong>PortalName  </strong>is checked against configured portals in the web.config file.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;microsoft.xrm.portal&gt;
 &lt;portals&gt;
 &lt;add name=&quot;Customer Portal&quot;/&gt;
 &lt;/portals&gt;
&lt;/microsoft.xrm.portal&gt;</pre>
<p>This value should be the value of Name attribute (adx_name) of Website entity (adx_website) contained in portalbase solution.</p>
<p>Assume we have the following website created in CRM</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/website.jpg"><img class="alignnone size-medium wp-image-213" title="website" src="http://zhongchenzhou.files.wordpress.com/2012/04/website.jpg?w=300&#038;h=40" alt="" width="300" height="40" /></a></p>
<p>two portals configured in web.config for each website inside CRM</p>
<pre class="brush: xml; title: ; notranslate">

&lt;microsoft.xrm.portal&gt;
 &lt;portals&gt;
 &lt;add name=&quot;Customer Portal&quot;/&gt;
 &lt;add name=&quot;Test Portal&quot;/&gt;
 &lt;/portals&gt;
&lt;/microsoft.xrm.portal&gt;</pre>
<p><strong>SiteMarkerName </strong>is the value of Name attribute (adx_name) of Site Marker entity (adx_sitemarker) contained in portalbase solution.</p>
<p><strong>QueryString</strong> value will be appended to the rendered url as query string.</p>
<p>The Web Page (adx_webpage) entity (related to the Site Marker entity (adx_sitemarker) with the name specified) will be retrieved from CRM first, and the Partial Url (adx_partialurl) attribute value will be used to construct the URL.</p>
<p>Example:</p>
<p><a href="https://zhongchenzhou.files.wordpress.com/2012/05/site-marker.png"><img class="alignnone size-medium wp-image-424" title="site marker" src="https://zhongchenzhou.files.wordpress.com/2012/05/site-marker.png?w=300&#038;h=97" alt="" width="300" height="97" /></a></p>
<p><a href="https://zhongchenzhou.files.wordpress.com/2012/05/web-page.png"><img class="alignnone size-medium wp-image-425" title="web page" src="https://zhongchenzhou.files.wordpress.com/2012/05/web-page.png?w=300&#038;h=118" alt="" width="300" height="118" /></a></p>
<p>The following markup</p>
<pre class="brush: xml; title: ; notranslate">&lt;crm:CrmHyperLink ID=&quot;CrmHyperLink1&quot; runat=&quot;server&quot; SiteMarkerName=&quot;KB Article&quot; /&gt;</pre>
<p>will be rendered as</p>
<pre class="brush: xml; title: ; notranslate">&lt;a id=&quot;Content_CrmHyperLink1&quot; href=&quot;/knowledge-base/article&quot;&gt;KB Article&lt;/a&gt;</pre>
<p>&nbsp;</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=423&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/05/07/dynamics-crm-2011-portal-development-crmhyperlink/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/website.jpg?w=300" medium="image">
			<media:title type="html">website</media:title>
		</media:content>

		<media:content url="https://zhongchenzhou.files.wordpress.com/2012/05/site-marker.png?w=300" medium="image">
			<media:title type="html">site marker</media:title>
		</media:content>

		<media:content url="https://zhongchenzhou.files.wordpress.com/2012/05/web-page.png?w=300" medium="image">
			<media:title type="html">web page</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Installation Error The instance name must be the same as computer name</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/29/dynamics-crm-2011-installation-error-the-instance-name-must-be-the-same-as-computer-name/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/29/dynamics-crm-2011-installation-error-the-instance-name-must-be-the-same-as-computer-name/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 05:00:51 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=399</guid>
		<description><![CDATA[When install Dynamics CRM 2011 Server, you may come across this error on System Checks screen; it is related to Microsoft SQL Server and the information is &#8220;The instance name must be the same as computer name.&#8221;. This can happen &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/29/dynamics-crm-2011-installation-error-the-instance-name-must-be-the-same-as-computer-name/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=399&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When install Dynamics CRM 2011 Server, you may come across this error on System Checks screen; it is related to Microsoft SQL Server and the information is &#8220;The instance name must be the same as computer name.&#8221;.</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/installerror.png"><img class="alignnone size-medium wp-image-400" title="installerror" src="http://zhongchenzhou.files.wordpress.com/2012/04/installerror.png?w=300&#038;h=259" alt="" width="300" height="259" /></a></p>
<p>This can happen if you rename the database server computer name after you have installed SQL Server.</p>
<p><strong>1. figure out what is saved in SQL Server:</strong></p>
<pre class="brush: sql; title: ; notranslate">select @@servername</pre>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/selectservername.png"><img class="alignnone size-medium wp-image-401" title="selectservername" src="http://zhongchenzhou.files.wordpress.com/2012/04/selectservername.png?w=300&#038;h=153" alt="" width="300" height="153" /></a></p>
<pre class="brush: sql; title: ; notranslate">SP_HELPSERVER</pre>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/sphelpserver.png"><img class="alignnone size-medium wp-image-402" title="sphelpserver" src="http://zhongchenzhou.files.wordpress.com/2012/04/sphelpserver.png?w=300&#038;h=81" alt="" width="300" height="81" /></a><br />
<strong>2. figure out the database computer name</strong>, Start -&gt; Computer -&gt; Properties</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/computername.png"><img class="alignnone size-medium wp-image-403" title="computername" src="http://zhongchenzhou.files.wordpress.com/2012/04/computername.png?w=300&#038;h=199" alt="" width="300" height="199" /></a></p>
<p><strong>3. drop invalid computer name saved in SQL Server</strong></p>
<pre class="brush: sql; title: ; notranslate">SP_DROPSERVER &quot;INVALID SERVER NAME&quot;</pre>
<p><strong>4. add correct computer name to SQL Server</strong></p>
<pre class="brush: sql; title: ; notranslate">SP_ADDSERVER &quot;CORRECT SERVER NAME&quot;, local</pre>
<p><strong>5. restart the MSSQLSERVER service</strong></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=399&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/29/dynamics-crm-2011-installation-error-the-instance-name-must-be-the-same-as-computer-name/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/installerror.png?w=300" medium="image">
			<media:title type="html">installerror</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/selectservername.png?w=300" medium="image">
			<media:title type="html">selectservername</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/sphelpserver.png?w=300" medium="image">
			<media:title type="html">sphelpserver</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/computername.png?w=300" medium="image">
			<media:title type="html">computername</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM send email within workflow permission trick</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-send-email-within-workflow-permission-trick/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-send-email-within-workflow-permission-trick/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 02:17:06 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=373</guid>
		<description><![CDATA[When send email within workflow, the email send is executed under the workflow owner. In case that the From of the email is not the same as the workflow owner, in order to send the email successfully, the workflow owner &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-send-email-within-workflow-permission-trick/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=373&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When send email within workflow, the email send is executed under the workflow owner. In case that the From of the email is not the same as the workflow owner, in order to send the email successfully, the workflow owner need to be given &#8220;<strong>Send E-Mail as another user</strong>&#8221; proviledge; or you have to make sure that the email From user is the same as the workflow owner.</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/priviledgesetting.png"><img class="alignnone size-medium wp-image-374" title="priviledgesetting" src="http://zhongchenzhou.files.wordpress.com/2012/04/priviledgesetting.png?w=300&#038;h=148" alt="" width="300" height="148" /></a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=373&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-send-email-within-workflow-permission-trick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/priviledgesetting.png?w=300" medium="image">
			<media:title type="html">priviledgesetting</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Web Address &#8211; Xrm.Page.context.getServerUrl &#124; Record URL(Dynamic) workflow dynamic values</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-2011-web-address-xrm-page-context-getserverurl-record-urldynamic-workflow-dynamic-values/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-2011-web-address-xrm-page-context-getserverurl-record-urldynamic-workflow-dynamic-values/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 01:19:13 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=365</guid>
		<description><![CDATA[&#160; The value returned by previously mentioned two ways can be changed by modify Dynamics CRM Web Address within Deployment Manager. You can use the following to construct URL in FormLabrary Xrm.Page.context.getServerUrl &#38;&#38; Record URL(Dynamic) workflow dynamic values can return &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-2011-web-address-xrm-page-context-getserverurl-record-urldynamic-workflow-dynamic-values/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=365&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: jscript; title: ; notranslate">Xrm.Page.context.getServerUrl()</pre>
<p>&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">{Record URL(Dynamic)(Entity)}</pre>
<p>The value returned by previously mentioned two ways can be changed by modify <strong>Dynamics CRM Web Address</strong> within <strong>Deployment Manager</strong>.</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/deploymgr.png"><img class="alignnone size-medium wp-image-366" title="deploymgr" src="http://zhongchenzhou.files.wordpress.com/2012/04/deploymgr.png?w=241&#038;h=300" alt="" width="241" height="300" /></a><br />
<a href="http://zhongchenzhou.files.wordpress.com/2012/04/prop.png"><img class="alignnone size-medium wp-image-367" title="prop" src="http://zhongchenzhou.files.wordpress.com/2012/04/prop.png?w=300&#038;h=76" alt="" width="300" height="76" /></a><br />
<a href="http://zhongchenzhou.files.wordpress.com/2012/04/webaddr.png"><img class="alignnone size-medium wp-image-368" title="webaddr" src="http://zhongchenzhou.files.wordpress.com/2012/04/webaddr.png?w=273&#038;h=300" alt="" width="273" height="300" /></a></p>
<p>You can use the following to construct URL in FormLabrary</p>
<pre class="brush: jscript; title: ; notranslate">var serverUrl = document.location.protocol + '//' + document.location.host + '/' + Xrm.Page.context.getOrgUniqueName();</pre>
<p>Xrm.Page.context.getServerUrl &amp;&amp; Record URL(Dynamic) workflow dynamic values can return the base server URL which can be used either to construct web service URL (SOAP | REST) in FormLibrary or embed Record URL in a workflow.</p>
<p>According to SDK</p>
<p><q>The URL returned is the standard URL used to access the application. If you access the server locally using <a href="http://localhost" rel="nofollow">http://localhost</a> or use an IP address rather than the actual name of the server, this will not be reflected in the value returned by this function. This means that if you are making web service calls or accessing web resources, Internet Explorer will apply security settings that apply to requests that cross domains. To avoid this, always connect to Microsoft Dynamics CRM using the standard URL.</q></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=365&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/26/dynamics-crm-2011-web-address-xrm-page-context-getserverurl-record-urldynamic-workflow-dynamic-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/deploymgr.png?w=241" medium="image">
			<media:title type="html">deploymgr</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/prop.png?w=300" medium="image">
			<media:title type="html">prop</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/webaddr.png?w=273" medium="image">
			<media:title type="html">webaddr</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development – CrmDataSource</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/23/dynamics-crm-2011-portal-development-crmdatasource/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/23/dynamics-crm-2011-portal-development-crmdatasource/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 10:26:11 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=356</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development CrmDataSource data source control connects to Dynamics CRM and retrieve EntityCollection and make it available for other controls to bind to, without requiring code. It supports Select, Create, Update and Delete data. 1. Select It supports FetchXml and QueryByAttribute to &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/23/dynamics-crm-2011-portal-development-crmdatasource/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=356&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p>CrmDataSource data source control connects to Dynamics CRM and retrieve EntityCollection</p>
<pre class="brush: csharp; title: ; notranslate">IOrganizationService.RetrieveMultiple(QueryExpression)
IOrganizationService.RetrieveMultiple(QueryByAttribute)
</pre>
<p>and make it available for other controls to bind to, without requiring code. It supports Select, Create, Update and Delete data.</p>
<p><strong>1. Select</strong></p>
<p>It supports FetchXml and QueryByAttribute to retrieve EntityCollection.</p>
<p><strong>I: FetchXml</strong></p>
<p>FetchXml string can be specified inside &lt;FetchXml&gt;&lt;/FetchXml&gt; node and parameters can be specified by using &lt;SelectParameters&gt;&lt;/SelectParameters&gt; node. Parameters in FetchXml must be prefixed with &#8220;@&#8221; symbol. System.Text.RegularExpressions.Regex.Replace is used to replace the parameter names with a value provided.</p>
<p>Example:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;crm:CrmDataSource ID=&quot;CrmDataSource1&quot; runat=&quot;server&quot;&gt;
 &lt;FetchXml&gt;
 &lt;fetch version=&quot;1.0&quot; output-format=&quot;xml-platform&quot; mapping=&quot;logical&quot; distinct=&quot;false&quot;&gt;
 &lt;entity name=&quot;adx_webpage&quot;&gt;
 &lt;attribute name=&quot;adx_webpageid&quot; /&gt;
 &lt;attribute name=&quot;adx_name&quot; /&gt;
 &lt;attribute name=&quot;createdon&quot; /&gt;
 &lt;order attribute=&quot;adx_name&quot; descending=&quot;false&quot; /&gt;
 &lt;filter type=&quot;and&quot;&gt;
 &lt;condition attribute=&quot;adx_name&quot; operator=&quot;eq&quot; value=&quot;@name&quot; /&gt;
 &lt;/filter&gt;
 &lt;/entity&gt;
 &lt;/fetch&gt;
 &lt;/FetchXml&gt;
 &lt;SelectParameters&gt;
 &lt;asp:Parameter Name=&quot;name&quot; DefaultValue=&quot;Cases&quot; /&gt;
 &lt;/SelectParameters&gt;
&lt;/crm:CrmDataSource&gt;
&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; DataSourceID=&quot;CrmDataSource1&quot;&gt;

&lt;Columns&gt;
 &lt;asp:BoundField DataField='adx_name' HeaderText=&quot;Name&quot; /&gt;
 &lt;asp:BoundField DataField='createdon' HeaderText=&quot;Created On&quot; /&gt;
 &lt;/Columns&gt;
 &lt;/asp:GridView&gt;</pre>
<p>Results:</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/fetchxml.png"><img class="alignnone size-medium wp-image-357" title="fetchxml" src="http://zhongchenzhou.files.wordpress.com/2012/04/fetchxml.png?w=300&#038;h=113" alt="" width="300" height="113" /></a></p>
<p><strong>II: QueryByAttribute</strong></p>
<p>QueryByAttribute can be specified inside &lt;QueryByAttribute&gt;&lt;/QueryByAttribute&gt; node and parameters can be specified by using &lt;SelectParameters&gt;&lt;/SelectParameters&gt; node. Parameters specified in QueryByAttribute must be prefixed with &#8220;@&#8221; symbol.</p>
<p><strong>EntityName, Attributes, Values, ColumnSet, Orders are implicit parameter names</strong>, which can be specified as parameter name in &lt;SelectParameters&gt;&lt;/SelectParameters&gt; node.</p>
<p><strong>While &lt;SelectParameters&gt; can be used to provide values to any parameters defined in &lt;QueryByAttribute&gt;&lt;/QueryByAttribute&gt; node; &lt;QueryParameters&gt;&lt;/QueryParameters&gt; values are only added to QueryByAttribute.Attributes and QueryByAttribute.Values.</strong></p>
<p><strong>Example:</strong></p>
<pre class="brush: xml; title: ; notranslate">

&lt;crm:CrmDataSource ID=&quot;CrmDataSource1&quot; runat=&quot;server&quot;&gt;
 &lt;QueryByAttribute EntityName=&quot;adx_webpage&quot;&gt;
 &lt;Attributes&gt;
 &lt;asp:ListItem Value=&quot;@queryAttr&quot;&gt;&lt;/asp:ListItem&gt;
 &lt;/Attributes&gt;
 &lt;ColumnSet&gt;
 &lt;asp:ListItem Value=&quot;adx_webpageid&quot;&gt;&lt;/asp:ListItem&gt;
 &lt;asp:ListItem Value=&quot;adx_name&quot;&gt;&lt;/asp:ListItem&gt;
 &lt;asp:ListItem Value=&quot;@timestamp&quot;&gt;&lt;/asp:ListItem&gt;
 &lt;/ColumnSet&gt;
 &lt;Orders&gt;
 &lt;asp:ListItem Text=&quot;desc&quot; Value=&quot;adx_name&quot;&gt;&lt;/asp:ListItem&gt;
 &lt;/Orders&gt;
 &lt;Values&gt;
 &lt;asp:ListItem Value=&quot;Home&quot;&gt;&lt;/asp:ListItem&gt;
 &lt;/Values&gt;
 &lt;/QueryByAttribute&gt;
 &lt;SelectParameters&gt;
 &lt;asp:Parameter Name=&quot;timestamp&quot; DefaultValue=&quot;createdon&quot; /&gt;
 &lt;asp:Parameter Name=&quot;queryAttr&quot; DefaultValue=&quot;adx_name&quot; /&gt;
 &lt;/SelectParameters&gt;
 &lt;QueryParameters&gt;
 &lt;asp:Parameter Name=&quot;adx_name&quot; DefaultValue=&quot;Home&quot; /&gt;
 &lt;/QueryParameters&gt;
 &lt;/crm:CrmDataSource&gt;
 &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; DataSourceID=&quot;CrmDataSource1&quot;&gt;
 &lt;Columns&gt;
 &lt;asp:BoundField DataField='adx_name' HeaderText=&quot;Name&quot; /&gt;
 &lt;asp:BoundField DataField='createdon' HeaderText=&quot;Created On&quot; /&gt;
 &lt;/Columns&gt;
 &lt;/asp:GridView&gt;</pre>
<p><strong>Result:</strong></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/querybyattribute.png"><img class="alignnone size-medium wp-image-361" title="querybyattribute" src="http://zhongchenzhou.files.wordpress.com/2012/04/querybyattribute.png?w=300&#038;h=114" alt="" width="300" height="114" /></a></p>
<p>2. Update</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=356&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/23/dynamics-crm-2011-portal-development-crmdatasource/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/fetchxml.png?w=300" medium="image">
			<media:title type="html">fetchxml</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/querybyattribute.png?w=300" medium="image">
			<media:title type="html">querybyattribute</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Diagnostics Tool for On Premise Update Rollup 4</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/18/dynamics-crm-2011-diagnostics-tool-for-on-premise-update-rollup-4/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/18/dynamics-crm-2011-diagnostics-tool-for-on-premise-update-rollup-4/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 02:47:49 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=351</guid>
		<description><![CDATA[http://&#60;serverUrl&#62;/tools/diagnostics/diag.aspx Filed under: Microsoft Dynamics CRM Tagged: Microsoft Dynamics CRM<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=351&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong><a href="http://&lt;serverUrl&gt;/tools/diagnostics/diag.aspx" rel="nofollow">http://&lt;serverUrl&gt;/tools/diagnostics/diag.aspx</a></strong></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=351&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/18/dynamics-crm-2011-diagnostics-tool-for-on-premise-update-rollup-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 SDK assembly is .NET 4 assembly using CLR V4 GAC location %windir%\Microsoft.NET\assembly\GAC_MSIL\</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/18/dynamics-crm-2011-sdk-assembly-is-net-4-assembly-using-clr-v4-gac-location-windir-microsoft-net-assembly-gac_msil/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/18/dynamics-crm-2011-sdk-assembly-is-net-4-assembly-using-clr-v4-gac-location-windir-microsoft-net-assembly-gac_msil/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 00:20:47 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=341</guid>
		<description><![CDATA[Dynamics CRM 2011 SDK assembly is .NET 4 assembly using CLR V4. CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC. Gacutil.exe can be used to install .NET 4 assembly into GAC. Gacutil.exe (Global Assembly Cache Tool) &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/18/dynamics-crm-2011-sdk-assembly-is-net-4-assembly-using-clr-v4-gac-location-windir-microsoft-net-assembly-gac_msil/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=341&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Dynamics CRM 2011 SDK assembly is .NET 4 assembly using CLR V4.</p>
<p><strong>CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC.</strong></p>
<p><strong>Gacutil.exe</strong> can be used to install .NET 4 assembly into GAC.</p>
<p><a title="Gacutil.exe (Global Assembly Cache Tool)" href="http://msdn.microsoft.com/en-us/library/ex0ss12c(v=vs.110).aspx" target="_blank">Gacutil.exe (Global Assembly Cache Tool)</a></p>
<p>The physical location is<br />
<strong>%windir%\Microsoft.NET\assembly\GAC_MSIL\</strong></p>
<p>.NET 2 &amp; .NET 3.5 assembly using CLR V2 and the GAC location is<br />
<strong>%windir%\assembly\</strong></p>
<p>1. Check assembly CLR version use <strong>IL Disassembler</strong></p>
<p>Start -&gt; All Programs -&gt; Microsoft Visual Studio 2010 -&gt; Microsoft Windows SDK Tools -&gt; IL Disassembler -&gt; File -&gt; Open -&gt; Double Click &#8220;MANIFEST&#8221;</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/ildis.png"><img class="alignnone size-medium wp-image-342" title="ildis" src="http://zhongchenzhou.files.wordpress.com/2012/04/ildis.png?w=156&#038;h=300" alt="" width="156" height="300" /></a></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/ildisresult.png"><img class="alignnone size-medium wp-image-343" title="ildisresult" src="http://zhongchenzhou.files.wordpress.com/2012/04/ildisresult.png?w=164&#038;h=300" alt="" width="164" height="300" /></a></p>
<p>2. Check assembly CLR version use <strong>C# code</strong></p>
<pre class="brush: csharp; title: ; notranslate">
string assemblyPath = @&quot;D:\sdk 5.0.10\bin\microsoft.xrm.sdk.dll&quot;;
string clrVersion = System.Reflection.Assembly.ReflectionOnlyLoadFrom(assemblyPath).ImageRuntimeVersion;
Console.WriteLine(clrVersion);
</pre>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/consoleresult.png"><img class="alignnone size-medium wp-image-344" title="consoleresult" src="http://zhongchenzhou.files.wordpress.com/2012/04/consoleresult.png?w=300&#038;h=31" alt="" width="300" height="31" /></a></p>
<p>3. View assembly in .NET 4 GAC using <strong>Gacutil.exe</strong></p>
<pre class="brush: plain; title: ; notranslate">
gacutil -l &gt;&quot;D:\gac.txt&quot;
</pre>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/gacutilresult.png"><img class="alignnone size-medium wp-image-345" title="gacutilresult" src="http://zhongchenzhou.files.wordpress.com/2012/04/gacutilresult.png?w=300&#038;h=65" alt="" width="300" height="65" /></a></p>
<p>4. View assembly in .NET 4 GAC using <strong>Windows Explorer</strong></p>
<p><strong>%windir%\Microsoft.NET\assembly\GAC_MSIL\</strong></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/explorerresult.png"><img class="alignnone size-medium wp-image-346" title="explorerresult" src="http://zhongchenzhou.files.wordpress.com/2012/04/explorerresult.png?w=300&#038;h=80" alt="" width="300" height="80" /></a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=341&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/18/dynamics-crm-2011-sdk-assembly-is-net-4-assembly-using-clr-v4-gac-location-windir-microsoft-net-assembly-gac_msil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/ildis.png?w=156" medium="image">
			<media:title type="html">ildis</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/ildisresult.png?w=164" medium="image">
			<media:title type="html">ildisresult</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/consoleresult.png?w=300" medium="image">
			<media:title type="html">consoleresult</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/gacutilresult.png?w=300" medium="image">
			<media:title type="html">gacutilresult</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/explorerresult.png?w=300" medium="image">
			<media:title type="html">explorerresult</media:title>
		</media:content>
	</item>
		<item>
		<title>Team Foundation 11 Deploy check in policy</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/16/team-foundation-11-deploy-check-in-policy/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/16/team-foundation-11-deploy-check-in-policy/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 12:13:34 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Team Foundation]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=338</guid>
		<description><![CDATA[Add string value registry key, specify file name of the compiled DLL assembliy and the full path under the following key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\TeamFoundation\SourceControl\Checkin Policies HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\TeamFoundation\SourceControl\Checkin Policies Filed under: Team Foundation Tagged: Team Foundation<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=338&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Add string value registry key, specify file name of the compiled DLL assembliy and the full path under the following key</p>
<p>HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\TeamFoundation\SourceControl\Checkin Policies</p>
<p>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\TeamFoundation\SourceControl\Checkin Policies</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/team-foundation/'>Team Foundation</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/team-foundation/'>Team Foundation</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=338&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/16/team-foundation-11-deploy-check-in-policy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM retrieve revenue attribute from lead entity will get transactioncurrencyid returned as well</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-retrieve-revenue-attribute-from-lead-entity-will-get-transactioncurrencyid-returned-as-well/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-retrieve-revenue-attribute-from-lead-entity-will-get-transactioncurrencyid-returned-as-well/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 06:49:49 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=335</guid>
		<description><![CDATA[will return lead entity with id, revenue and transactioncurrencyid attributes, if they are not null. Filed under: Microsoft Dynamics CRM Tagged: Microsoft Dynamics CRM<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=335&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: csharp; title: ; notranslate">
IOrganizationService.Retrieve(&quot;lead&quot;, id, new ColumnSet(&quot;revenue&quot;));
</pre>
<p>will return lead entity with id, revenue and transactioncurrencyid attributes, if they are not null.</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/leadrevenueresult.png"><img class="alignnone size-medium wp-image-336" title="leadrevenueresult" src="http://zhongchenzhou.files.wordpress.com/2012/04/leadrevenueresult.png?w=300&#038;h=64" alt="" width="300" height="64" /></a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=335&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-retrieve-revenue-attribute-from-lead-entity-will-get-transactioncurrencyid-returned-as-well/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/leadrevenueresult.png?w=300" medium="image">
			<media:title type="html">leadrevenueresult</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development – SavedQueryDataSource</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-savedquerydatasource/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-savedquerydatasource/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 02:27:24 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=327</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development SavedQueryDataSource data source control connects to Dynamics CRM and retrieve  savedquery entity, convert its fetchxml to QueryExpression, retrieve entities by using IOrganizationService.RetrieveMultiple(QueryExpression) and make these entities available for other controls to bind to, without requiring code. It only supports retrieving &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-savedquerydatasource/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=327&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p>SavedQueryDataSource data source control connects to Dynamics CRM and retrieve  <strong>savedquery</strong> entity, convert its fetchxml to QueryExpression, retrieve entities by using IOrganizationService.RetrieveMultiple(QueryExpression) and make these entities available for other controls to bind to, without requiring code. It only supports retrieving data.</p>
<p>It only works with savedquery <strong>NOT</strong> userquery. <strong>Savedquery</strong> is available to the entire organization and created using customization; <strong>userquery</strong> belongs to individual users and created using advanced find user interface.</p>
<p><strong>Example:</strong></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/resultincrm.jpg"><img class="alignnone size-medium wp-image-330" title="resultincrm" src="http://zhongchenzhou.files.wordpress.com/2012/04/resultincrm.jpg?w=300&#038;h=126" alt="" width="300" height="126" /></a></p>
<pre class="brush: xml; title: ; notranslate">

&lt;crm:SavedQueryDataSource ID=&quot;SavedQueryDataSource1&quot; runat=&quot;server&quot; SavedQueryName=&quot;Active WebPages&quot;&gt;
 &lt;/crm:SavedQueryDataSource&gt;
 &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; DataSourceID=&quot;SavedQueryDataSource1&quot;&gt;
 &lt;/asp:GridView&gt;</pre>
<p><strong>Results:</strong></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/resultinportal1.jpg"><img class="alignnone size-thumbnail wp-image-332" title="resultinportal" src="http://zhongchenzhou.files.wordpress.com/2012/04/resultinportal1.jpg?w=150&#038;h=115" alt="" width="150" height="115" /></a></p>
<p>More Information:</p>
<p><a title="Use Saved Queries in a Portal" href="http://msdn.microsoft.com/en-us/library/gg695802.aspx#use_saved_Queries" target="_blank">Use Saved Queries in a Portal</a></p>
<p><a title="Walkthrough: Build a Web Application That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions" href="http://msdn.microsoft.com/en-us/library/gg695790.aspx" target="_blank">Walkthrough: Build a Web Application That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions</a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=327&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-savedquerydatasource/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/resultincrm.jpg?w=300" medium="image">
			<media:title type="html">resultincrm</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/resultinportal1.jpg?w=150" medium="image">
			<media:title type="html">resultinportal</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development – CrmEntityDataSource</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-crmentitydatasource/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-crmentitydatasource/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 01:07:51 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=322</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development CrmEntityDataSource data source control expose a property &#8220;DataItem&#8221; of type object and make it available for other controls to bind to, without requiring code. It only supports retrieving value from CrmEntityDataSource.DataItem property. If CrmSiteMapNode is assigned as the value &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-crmentitydatasource/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=322&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p><strong>CrmEntityDataSource </strong>data source control expose a property &#8220;<strong>DataItem</strong>&#8221; of type object and make it available for other controls to bind to, without requiring code. It only supports retrieving value from <strong>CrmEntityDataSource.DataItem</strong> property.</p>
<p>If <strong>CrmSiteMapNode</strong> is assigned as the value for DataItem property, then the return value will be<br />
<strong>new Entity[] { CrmSiteMapNode.Entity }</strong>,<br />
otherwise it will be<br />
<strong>new object[] { CrmEntityDataSource.DataItem }.</strong></p>
<p>DataItem property can be set in the .aspx markup by using ASP.NET Expressions/ExpressionBuilder (e.g. <a title="Dynamics CRM 2011 Portal Development – CrmSiteMap Expression" href="http://zhongchenzhou.wordpress.com/2012/04/03/dynamics-crm-2011-portal-development-crsitemap-expression/" target="_blank">CrmSiteMap Expression</a>).</p>
<p>More information regarding to ASP.NET expression can be found <a title="ASP.NET Expressions Overview" href="http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx" target="_blank">ASP.NET Expressions Overview</a>  and <a title="ExpressionBuilder Class" href="http://msdn.microsoft.com/en-us/library/system.web.compilation.expressionbuilder.aspx" target="_blank">ExpressionBuilder Class</a>.</p>
<p>DataItem property can also be set in the .cs code behind.</p>
<p>Example:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;crm:CrmEntityDataSource ID=&quot;CrmEntityDataSource1&quot; runat=&quot;server&quot; DataItem='&lt;%$ CrmSiteMap: Current %&gt;'&gt;
 &lt;/crm:CrmEntityDataSource&gt;
 &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; DataSourceID=&quot;CrmEntityDataSource1&quot;&gt;
 &lt;/asp:GridView&gt;
</pre>
<p>Result:</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/result2.jpg"><img class="alignnone size-medium wp-image-323" title="result" src="http://zhongchenzhou.files.wordpress.com/2012/04/result2.jpg?w=300&#038;h=116" alt="" width="300" height="116" /></a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=322&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-crmentitydatasource/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/result2.jpg?w=300" medium="image">
			<media:title type="html">result</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET inline expressions</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/16/asp-net-inline-expressions/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/16/asp-net-inline-expressions/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 00:36:13 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=320</guid>
		<description><![CDATA[&#60;% &#8230; %&#62; Embedded Code Blocks in ASP.NET Web Pages Server tags cannot contain &#60;% &#8230; %&#62; constructs The code in the block can execute programming statements and call functions in the current page class during the page-rendering phase. &#60;%= &#8230; &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/16/asp-net-inline-expressions/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=320&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h3><strong>&lt;% &#8230; %&gt; </strong><a title="Embedded Code Blocks in ASP.NET Web Pages" href="http://msdn.microsoft.com/en-us/library/ms178135.aspx" target="_blank"><strong>Embedded Code Blocks in ASP.NET Web Pages</strong></a></h3>
<h3>Server tags cannot contain &lt;% &#8230; %&gt; constructs<br />
The code in the block can execute programming statements and call functions in the current page class during the page-rendering phase.</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;%@ Page Language=&quot;VB&quot; %&gt;
&lt;html&gt;
&lt;body&gt;
 &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
 &lt;% For i As Integer = 16 To 24 Step 2%&gt;
 &lt;div style=&quot;font-size: &lt;% Response.Write(i)%&gt;&quot;&gt;
 Hello World&lt;br /&gt;
 &lt;/div&gt;
 &lt;% Next%&gt;
 &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3><strong>&lt;%= &#8230; %&gt; </strong><a title="Displaying from ASP.NET" href="http://msdn.microsoft.com/en-us/library/6dwsdcf5.aspx" target="_blank"><strong>displaying expression</strong></a></h3>
<h3>equivalent of the embedded code block that contains only the Response.Write(…) statement. This is the simplest way to display information such as a single string, an int variable, or a constant.<br />
displaying expression cannot be used in the attributes of server controls. This is because the .NET Framework directly compiles the whole expression instead of the displaying content as the value to the attribute.</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;%@ Page Language=&quot;VB&quot; %&gt;
&lt;html&gt;
&lt;body&gt;
 &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
 &lt;%=DateTime.Now.ToString() %&gt;
 &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3 id="tocHeadRef"><strong>&lt;%@ &#8230; %&gt; <a href="http://msdn.microsoft.com/en-us/library/xz702w3e.aspx" target="_blank">directive expression</a></strong></h3>
<h3 id="tocHeadRef"><strong>&lt;%# &#8230; %&gt; <a title="Data-Binding Expression Syntax" href="http://msdn.microsoft.com/en-us/library/bda9bbfx.aspx" target="_blank">data-binding expression</a></strong></h3>
<h3>The data-binding expression creates binding between a server control property and a data source when the control’s DataBind method of this server control is called on the page.</h3>
<h3 id="tocHeadRef"><strong>&lt;%$ &#8230; %&gt; <a title="ASP.NET Expressions Overview" href="http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx" target="_blank">expression builder</a></strong></h3>
<p>More information regarding to ASP.NET expression can be found <a title="ASP.NET Expressions Overview" href="http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx" target="_blank">ASP.NET Expressions Overview</a>  and <a title="ExpressionBuilder Class" href="http://msdn.microsoft.com/en-us/library/system.web.compilation.expressionbuilder.aspx" target="_blank">ExpressionBuilder Class</a>.</p>
<h3 id="tocHeadRef"><strong>&lt;%&#8211; &#8230; &#8212; %&gt; <a title="Server-Side Comments" href="http://msdn.microsoft.com/en-us/library/4acf8afk.aspx" target="_blank">server-side comments block</a></strong></h3>
<p><strong>&lt;!&#8211; #include file|virtual=&#8221;filename&#8221; &#8211;&gt; <a title="Server-Side Include Directive Syntax" href="http://msdn.microsoft.com/en-us/library/3207d0e3.aspx" target="_blank">Server-Side Include Directive Syntax</a></strong></p>
<p>More information:</p>
<p><a title="Introduction to ASP.NET inline expressions in the .NET Framework" href="http://support.microsoft.com/kb/976112" target="_blank">Introduction to ASP.NET inline expressions in the .NET Framework</a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/asp-net/'>ASP.NET</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/asp-net/'>ASP.NET</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=320&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/16/asp-net-inline-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Microsoft Sync Framework Simple Provider &#8211; Concurrency Conflict Handling</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/12/microsoft-sync-framework-simple-provider-conflict-handling/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/12/microsoft-sync-framework-simple-provider-conflict-handling/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 07:12:18 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Sync Framework]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=306</guid>
		<description><![CDATA[The destination provider is responsible to resolve conflicts. In order to resolve concurrency conflicts ConflictResolutionAction need to be set. This can be set by the sync framework automatically by specify ConflictResolutionPolicy value (ApplicationDefined, DestinationWins, SourceWins) to SimpleSyncProvider.Configuration. If you specify the value of ApplicationDefined &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/12/microsoft-sync-framework-simple-provider-conflict-handling/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=306&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The destination provider is responsible to resolve conflicts. In order to resolve concurrency conflicts ConflictResolutionAction need to be set. This can be set by the sync framework automatically by specify ConflictResolutionPolicy value (<strong>ApplicationDefined</strong>, <strong>DestinationWins</strong>, <strong>SourceWins</strong>) to <strong>SimpleSyncProvider.Configuration</strong>. If you specify the value of ApplicationDefined then ConflictResolutionAction  need to be set within  event handler of <strong>ItemConflicting</strong> event.</p>
<p><strong>1. ConflictResolutionAction.SkipChange</strong></p>
<pre class="brush: csharp; title: ; notranslate">
e.SetResolutionAction(ConflictResolutionAction.SkipChange);
</pre>
<p>Neither source nor destination data store is updated.</p>
<p>It will be reflected through <strong>SyncOperationStatistics.DownloadChangesFailed</strong> or <strong>SyncOperationStatistics.UploadChangesFailed</strong>.</p>
<p>It will be counted as <strong>SyncOperationStatistics.DownloadChangesTotal</strong> or <strong>SyncOperationStatistics.UploadChangesTotal</strong>; because <strong>LoadChangeData</strong> is called on source provider.</p>
<p><strong>ItemConflicting</strong> event will be raised for the same record during the next sync session.</p>
<p><strong>2. ConflictResolutionAction.SaveConflict</strong></p>
<p>The same effect as ConflictResolutionAction.SkipChange but with LoadChangeData is call one more time on source data source after ItemConflicting event is raised.</p>
<p><strong>3. ConflictResolutionAction.DestinationWins</strong></p>
<p>Based on the SyncDirectionOrder setting; source data store may be updated.</p>
<p>It will be reflected through <strong>SyncOperationStatistics.DownloadChangesApplied</strong> or <strong>SyncOperationStatistics.UploadChangesApplied</strong>.</p>
<p>It will be counted as <strong>SyncOperationStatistics.DownloadChangesTotal</strong> or <strong>SyncOperationStatistics.UploadChangesTotal.</strong></p>
<p><strong>ItemConflicting</strong> event will <strong>NOT</strong> be raised for the same record during the next sync session.</p>
<p><strong>4. ConflictResolutionAction.SourceWins</strong></p>
<p>Based on the SyncDirectionOrder setting; destination data store may be updated.</p>
<p>It will be reflected through <strong>SyncOperationStatistics.DownloadChangesApplied</strong> or <strong>SyncOperationStatistics.UploadChangesApplied</strong>.</p>
<p>It will be counted as <strong>SyncOperationStatistics.DownloadChangesTotal</strong> or <strong>SyncOperationStatistics.UploadChangesTotal.</strong></p>
<p><strong>ItemConflicting</strong> event will <strong>NOT</strong> be raised for the same record during the next sync session.</p>
<p><strong>5. ConflictResolutionAction.Merge</strong></p>
<p>When set resolution action to ConflictResolutionAction.Merge, <strong>ISimpleSyncProviderConcurrencyConflictResolver</strong> Interface need to be implemented. Based on the type of concurrency conflict the following three method will be called. <strong>ResolveLocalDeleteRemoteUpdateConflict</strong>, <strong>ResolveLocalUpdateRemoteDeleteConflict</strong> and <strong>ResolveUpdateUpdateConflict</strong>. Otherwise if these method is not implemented, it is treated as ConflictResolutionAction.SaveConflict.</p>
<p>You have to perform Create, Update, Delete operation in these three methods as the results of the resolution. (Except if a delete is the result of the resolution in either ResolveLocalDeleteRemoteUpdateConflict or ResolveLocalUpdateRemoteDeleteConflict, in this case SyncOrchestrator will invoke DeleteItem on the other provider)</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-sync-framework/'>Microsoft Sync Framework</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-sync-framework/'>Microsoft Sync Framework</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=306&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/12/microsoft-sync-framework-simple-provider-conflict-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development – CrmMetadataDataSource</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/11/dynamics-crm-2011-portal-development-crmmetadatadatasource/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/11/dynamics-crm-2011-portal-development-crmmetadatadatasource/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 02:53:51 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=295</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development CrmMetadataDataSource data source control connects to Dynamics CRM and retrieve  Metadata and make it available for other controls to bind to, without requiring code. It only supports retrieving data. It can retrieve metadata for all entities (EntityMetadata[]) filtered by EntityFilters enum value &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/11/dynamics-crm-2011-portal-development-crmmetadatadatasource/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=295&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p>CrmMetadataDataSource data source control connects to Dynamics CRM and retrieve  Metadata and make it available for other controls to bind to, without requiring code. It only supports retrieving data.</p>
<p>It can retrieve metadata for all entities (<strong>EntityMetadata[]</strong>) filtered by EntityFilters enum value set through MetadataFlags, attributes metadata for one single entity (<strong>AttributeMetadata[]</strong>) filter by EntityFilters enum value set through EntityFlags, and attribute metadata of type PicklistAttributeMetadata/StatusAttributeMetadata/StateAttributeMetadata  for one single entity (<strong>IEnumerable &lt;new { sting OptionLabel, int OptionValue}&gt;</strong>) ordered by value specified in SortExpression.</p>
<p>SelectParameters is ignored while retrieve metadata from Dynamics CRM.</p>
<p><strong>Retrieve metadata for all entities</strong></p>
<p>To retrieve metadata for all entities, leave both EntityName and AttributeName empty, and optionally specify MetadataFlags to limit the amount of information returned. MetadataFlags takes a value of EntityFilters type.</p>
<pre class="brush: csharp; title: ; notranslate">
[Flags]
 public enum EntityFilters
 {
 All = 15,
 Attributes = 2,
 Default = 1,
 Entity = 1,
 Privileges = 4,
 Relationships = 8
 }</pre>
<p><strong>Example:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;crm:CrmMetadataDataSource ID=&quot;CrmMetadataDataSource1&quot; runat=&quot;server&quot; MetadataFlags=&quot;Attributes&quot;&gt;
&lt;/crm:CrmMetadataDataSource&gt;
&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; DataSourceID=&quot;CrmMetadataDataSource1&quot;&gt;
&lt;Columns&gt;
 &lt;asp:BoundField DataField=&quot;DisplayName.UserLocalizedLabel.Label&quot; HeaderText=&quot;Display Name&quot; /&gt;
 &lt;asp:TemplateField HeaderText=&quot;First Attribute&quot;&gt;
 &lt;ItemTemplate&gt;
 &lt;asp:Literal runat=&quot;server&quot; Text='&lt;%# Eval(&quot;Attributes[0].DisplayName.UserLocalizedLabel.Label&quot;) %&gt;' /&gt;
 &lt;/ItemTemplate&gt;
 &lt;/asp:TemplateField&gt;
 &lt;asp:TemplateField HeaderText=&quot;Second Attribute&quot;&gt;
 &lt;ItemTemplate&gt;
 &lt;asp:Literal runat=&quot;server&quot; Text='&lt;%# DataBinder.Eval(Container.DataItem, &quot;Attributes[1].DisplayName.UserLocalizedLabel.Label&quot;) %&gt;' /&gt;
 &lt;/ItemTemplate&gt;
 &lt;/asp:TemplateField&gt;
 &lt;asp:TemplateField HeaderText=&quot;Third Attribute&quot;&gt;
 &lt;ItemTemplate&gt;
 &lt;asp:Literal runat=&quot;server&quot; Text='&lt;%# ((EntityMetadata)Container.DataItem).Attributes[2].DisplayName.UserLocalizedLabel == null ? string.Empty : ((EntityMetadata)Container.DataItem).Attributes[2].DisplayName.UserLocalizedLabel.Label.ToLower() %&gt;' /&gt;
 &lt;/ItemTemplate&gt;
 &lt;/asp:TemplateField&gt;
 &lt;/Columns&gt;
 &lt;/asp:GridView&gt;</pre>
<p><strong>Result:</strong></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/allentitiesmetadata.jpg"><img class="alignnone size-medium wp-image-298" title="AllEntitiesMetadata" src="http://zhongchenzhou.files.wordpress.com/2012/04/allentitiesmetadata.jpg?w=300&#038;h=274" alt="" width="300" height="274" /></a></p>
<p><strong>Tips on Data-Binding Expressions</strong></p>
<p>1.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%# Eval(&quot;expression&quot;) %&gt;
</pre>
<p>is a short cut for</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%# DataBinder.Eval(Container.DataItem, &quot;expression&quot;) %&gt;
</pre>
<p>2. Container.DataItem can be used within &lt;%# and %&gt; delimiters to refer to  the current data item of the naming container.</p>
<p>3. Any publicly scoped code within the &lt;%# and %&gt;delimiters to execute that code and return a value during page processing.</p>
<p>4. For the cast ((EntityMetadata)Container.DataItem) in the example to work, register Microsoft.Xrm.Sdk.Metadata namespace in web.config</p>
<pre class="brush: xml; title: ; notranslate">
&lt;system.web&gt;
    &lt;pages viewStateEncryptionMode=&quot;Always&quot; validateRequest=&quot;true&quot;&gt;
        &lt;namespaces&gt;
            &lt;add namespace=&quot;Microsoft.Xrm.Sdk.Metadata&quot;/&gt;
        &lt;/namespaces&gt;
    &lt;/pages&gt;
&lt;/system.web&gt;
</pre>
<p>More information regarding to Data-Binding Expressions can be found <a title="Data-Binding Expressions Overview" href="http://msdn.microsoft.com/en-us/library/ms178366.aspx" target="_blank">Data-Binding Expressions Overview</a> and <a title="DataBinder.Eval Method" href="http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx" target="_blank">DataBinder.Eval Method</a></p>
<p><strong>Notes:</strong></p>
<p>At the moment there is a bug in Microsoft.Xrm.Client.Messages.OrganizationServiceContextExtensions.RetrieveAllEntities(this OrganizationServiceContext service, EntityFilters entityFilters = 1, bool retrieveAsIfPublished = false) method. Parameter with name &#8220;MetadataId&#8221; should not be added to the organization request, because this cause an exception with message &#8220;Unrecognized request parameter: MetadataId&#8221;.</p>
<p><strong>Retrieve metadata for one single entity</strong></p>
<p>To retrieve metadata for one single entity, leave AttributeName empty, specify EntityName and optionally specify EntityFlags  to limit the amount of information returned. EntityFlags  takes a value of EntityFilters type.</p>
<p>Example</p>
<pre class="brush: xml; title: ; notranslate">

&lt;crm:CrmMetadataDataSource ID=&quot;CrmMetadataDataSource2&quot; runat=&quot;server&quot; EntityName=&quot;account&quot; EntityFlags=&quot;All&quot;&gt;
 &lt;/crm:CrmMetadataDataSource&gt;
 &lt;asp:GridView ID=&quot;GridView2&quot; runat=&quot;server&quot; DataSourceID=&quot;CrmMetadataDataSource2&quot;&gt;
 &lt;Columns&gt;
 &lt;asp:BoundField DataField=&quot;DisplayName.UserLocalizedLabel.Label&quot; HeaderText=&quot;Display Name&quot; /&gt;
 &lt;/Columns&gt;
 &lt;/asp:GridView&gt;
</pre>
<p>Result</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/singleentitymetadata.jpg"><img class="alignnone size-medium wp-image-300" title="SingleEntityMetadata" src="http://zhongchenzhou.files.wordpress.com/2012/04/singleentitymetadata.jpg?w=300&#038;h=212" alt="" width="300" height="212" /></a></p>
<p><strong>Retrieve metadata for one attribute from specified entity</strong></p>
<p>To retrieve metadata for one attribute from specified entity, specify AttributeName and EntityName and optionally specify SortExpression to control the order (Value/OptionValue, Label/OptionLabel, State, DefaultStatus can be used to sort).</p>
<p>This is limited to attributes of type type PicklistAttributeMetadata, StatusAttributeMetadata or StateAttributeMetadata only. The return value will be of type (<strong>IEnumerable &lt;new { sting OptionLabel, int OptionValue}&gt;</strong>).</p>
<p><strong>Example:</strong></p>
<pre class="brush: xml; title: ; notranslate">

&lt;crm:CrmMetadataDataSource ID=&quot;CrmMetadataDataSource3&quot; runat=&quot;server&quot; EntityName=&quot;account&quot; AttributeName=&quot;industrycode&quot; SortExpression=&quot;Label DESC&quot;&gt;
 &lt;/crm:CrmMetadataDataSource&gt;
 &lt;asp:GridView ID=&quot;GridView3&quot; runat=&quot;server&quot; DataSourceID=&quot;CrmMetadataDataSource3&quot;&gt;
 &lt;/asp:GridView&gt;


</pre>
<p><strong>Result:</strong></p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/singleattributemetadata.jpg"><img class="alignnone size-medium wp-image-302" title="SingleAttributeMetadata" src="http://zhongchenzhou.files.wordpress.com/2012/04/singleattributemetadata.jpg?w=180&#038;h=300" alt="" width="180" height="300" /></a></p>
<p>More Information can be found <a title="Use CrmMetadataDataSource Control" href="http://msdn.microsoft.com/en-us/library/gg695802.aspx#use_crmmetadata" target="_blank">Use CrmMetadataDataSource Control</a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=295&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/11/dynamics-crm-2011-portal-development-crmmetadatadatasource/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/allentitiesmetadata.jpg?w=300" medium="image">
			<media:title type="html">AllEntitiesMetadata</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/singleentitymetadata.jpg?w=300" medium="image">
			<media:title type="html">SingleEntityMetadata</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/singleattributemetadata.jpg?w=180" medium="image">
			<media:title type="html">SingleAttributeMetadata</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 12:54:13 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=278</guid>
		<description><![CDATA[Microsoft Dynamics CRM 2011 SDK contains portal developer guide, assemblies and portalbase solution to help creating portal Web pages that interact with Microsoft Dynamics CRM. Microsoft Dynamics Labs has created “Customer Portal for Microsoft Dynamics CRM 2011” and “Partner Relationship &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=278&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Microsoft Dynamics CRM 2011 SDK" href="http://msdn.microsoft.com/en-us/library/gg309408.aspx" target="_blank">Microsoft Dynamics CRM 2011 SDK</a> contains <a title="portal developer guide" href="http://msdn.microsoft.com/en-us/library/gg695814.aspx" target="_blank">portal developer guide</a>, assemblies and portalbase solution to help creating portal Web pages that interact with Microsoft Dynamics CRM.</p>
<p><a title="Microsoft Dynamics Labs" href="http://dynamics-crm.pinpoint.microsoft.com/en-US/PartnerDetails.aspx?PartnerId=4297440805" target="_blank">Microsoft Dynamics Labs</a> has created “<a title="Customer Portal for Microsoft Dynamics CRM 2011" href="http://dynamics-crm.pinpoint.microsoft.com/en-US/applications/customer-portal-for-microsoft-dynamics-crm-2011-12884910826" target="_blank">Customer Portal for Microsoft Dynamics CRM 2011</a>” and “<a title="Partner Relationship Management Portal for Microsoft Dynamics CRM 2011" href="http://dynamics-crm.pinpoint.microsoft.com/en-US/applications/partner-relationship-management-portal-for-microsoft-dynamics-crm-2011-12884910828" target="_blank">Partner Relationship Management Portal for Microsoft Dynamics CRM 2011</a>” which can be accessed in <a title="Microsoft Dynamics market place" href="http://dynamics-crm.pinpoint.microsoft.com/en-US/home" target="_blank">Microsoft Dynamics market place</a>.</p>
<p>This article series introduce how to use assemblies (microsoft.xrm.client.dll &amp; microsoft.xrm.portal.dll) and portalbase solution to build portal.</p>
<ol>
<li><a title="Dynamics CRM 2011 Portal Development – Hello World" href="http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-hello-world/" target="_blank">Getting Started</a></li>
<li>ASP.NET Expression
<ul>
<li><a title="Permalink to Dynamics CRM 2011 Portal Development – Snippet/SiteSetting Expression" href="http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-asp-net-expressions/" rel="bookmark">Snippet/SiteSetting Expression</a></li>
<li><a title="Permalink to Dynamics CRM 2011 Portal Development – CrmSiteMap Expression" href="http://zhongchenzhou.wordpress.com/2012/04/03/dynamics-crm-2011-portal-development-crsitemap-expression/" rel="bookmark">CrmSiteMap Expression</a></li>
<li><a title="Permalink to Dynamics CRM 2011 Portal Development – PortalContext/CurrentContact/Website Expression" href="http://zhongchenzhou.wordpress.com/2012/04/04/dynamics-crm-2011-portal-development-portalcontex-expression/" rel="bookmark">PortalContext/CurrentContact/Website Expression</a></li>
<li><a title="Permalink to Dynamics CRM 2011 Portal Development – TimeZone Expression" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development-timezone-expression/" rel="bookmark">TimeZone Expression</a></li>
</ul>
</li>
<li>Data Source Web Server Controls
<ul>
<li><a title="Dynamics CRM 2011 Portal Development – CrmDataSource" href="http://zhongchenzhou.wordpress.com/2012/04/23/dynamics-crm-2011-portal-development-crmdatasource/" target="_blank">CrmDataSource</a></li>
<li><a title="Dynamics CRM 2011 Portal Development – CrmEntityDataSource" href="http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-crmentitydatasource/" target="_blank">CrmEntityDataSource</a></li>
<li><a title="Dynamics CRM 2011 Portal Development – CrmMetadataDataSource" href="http://zhongchenzhou.wordpress.com/2012/04/11/dynamics-crm-2011-portal-development-crmmetadatadatasource/" target="_blank">CrmMetadataDataSource</a></li>
<li><a title="Dynamics CRM 2011 Portal Development – SavedQueryDataSource" href="http://zhongchenzhou.wordpress.com/2012/04/16/dynamics-crm-2011-portal-development-savedquerydatasource/" target="_blank">SavedQueryDataSource</a></li>
</ul>
</li>
<li>ASP.NET Data-Bound Web Server Controls
<ul>
<li>CrmEntityEditingManager</li>
<li>CrmEntityFormView</li>
<li>CrmListView</li>
<li>CrmSiteMapChildView</li>
<li>Property</li>
<li>Snippet</li>
<li>WebLinks</li>
</ul>
</li>
<li>ASP.NET Web Server Controls
<ul>
<li><a title="Dynamics CRM 2011 Portal Development – CrmHyperLink" href="http://zhongchenzhou.wordpress.com/2012/05/07/dynamics-crm-2011-portal-development-crmhyperlink/" target="_blank">CrmHyperLink</a></li>
<li>DateTimeLiteral</li>
<li>EntityRightsView</li>
<li>LiveIdLoginStatus</li>
<li>WebLinkHyperLink</li>
<li>SiteEditingManager</li>
</ul>
</li>
</ol>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=278&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development – TimeZone Expression</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development-timezone-expression/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development-timezone-expression/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 12:48:01 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=275</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development TimeZone Expression Syntax: TimeZone Expression takes a format of comma separated name value pairs, any pair is optional and the name of the pair is optional as well. If name is omitted, then the sequence &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development-timezone-expression/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=275&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p><strong>TimeZone Expression</strong></p>
<p>Syntax:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%$ TimeZone: Name=name, Eval=eval, Format=format, Portal=portal%&gt;
&lt;%$ TimeZone: name, eval, format, portal%&gt;
</pre>
<p>TimeZone Expression takes a format of comma separated name value pairs, any pair is optional and the name of the pair is optional as well. If name is omitted, then the sequence is significant.</p>
<p>The first name value pair <strong>(Name)</strong> can be set to &#8220;id&#8221; or &#8221;displayname&#8221;. When it is set to &#8220;id&#8221; TimeZoneInfo.Id is the result of expression evaluation. When it is set to &#8220;displayname&#8221; TimeZoneInfo.DisplayName Id is the result of expression evaluation. When it is not specified , the following is returned.</p>
<pre class="brush: xml; title: ; notranslate">
System.Web.UI.DataBinder.Eval(TimeZoneInfo, eval, format)
</pre>
<p>A site setting named &#8220;timezone/id&#8221; is first checked, if it is not specified TimeZoneInfo.Local is used for the evaluation.</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=275&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development-timezone-expression/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development – PortalContext/CurrentContact/Website Expression</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/04/dynamics-crm-2011-portal-development-portalcontex-expression/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/04/dynamics-crm-2011-portal-development-portalcontex-expression/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 12:21:58 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=256</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development PortalContext Expression Syntax: PortalContext Expression takes a format of comma separated name value pairs, any pair is optional and the name of the pair is optional as well. If name is omitted, then the sequence &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/04/dynamics-crm-2011-portal-development-portalcontex-expression/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=256&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p><strong>PortalContext Expression</strong></p>
<p>Syntax:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%$ Context: Property=property, Attribute=attribute, Eval=eval, Format=format, Default=default, Portal=portal%&gt;
&lt;%$ Context: property, attribute, eval, format, default, portal%&gt;
</pre>
<p>PortalContext Expression takes a format of comma separated name value pairs, any pair is optional and the name of the pair is optional as well. If name is omitted, then the sequence is significant.</p>
<p>The first name value pair (<strong>Property</strong>) is the property name of IPortalContext instance. IPortalContext interface defined six properties:</p>
<pre class="brush: csharp; title: ; notranslate">
public interface IPortalContext
{
    Microsoft.Xrm.Sdk.Entity Entity { get; }
    string Path { get; }
    OrganizationServiceContext ServiceContext { get; }
    System.Net.HttpStatusCode StatusCode { get; }
    Microsoft.Xrm.Sdk.Entity User { get; }
    Microsoft.Xrm.Sdk.Entity Website { get; }
}
</pre>
<p>If &#8220;Current&#8221; is specified as the value, the current PortalContext instance will be the result of the expression. If any other valide IPortalContext property name is specified, that property value is retrieved for the rest of the expression evaluation. If that property is null and the expression should be evaluated to a string value then the default value specified in 5th name value pair will be the result of the expression. Otherwise null will be returned from expression evaluation.</p>
<p>The second name value pair <strong>(Attribute)</strong> is only effective if the property of the previously retrieve property of IPortalContext is an Entity. If property of IPortalContext is an Entity, will be used for the rest of the evaluation, otherwise IPortalContext.Property is used for the rest of the evaluation. The value will be either</p>
<pre class="brush: csharp; title: ; notranslate">
System.Web.UI.DataBinder.Eval(IPortalContext.Property[Attribute], eval, format)
</pre>
<p>or</p>
<pre class="brush: csharp; title: ; notranslate">
System.Web.UI.DataBinder.Eval(IPortalContext.Property, eval, format)
</pre>
<p><strong>Examples 1:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Context: Property=Path%&gt;&quot; /&gt;
</pre>
<p>will produce the following output</p>
<pre class="brush: plain; title: ; notranslate">
~/Pages/Home.aspx?pageid=978e66cc-c8c6-4e5c-9ce0-d6ff153e9722
</pre>
<p><strong>Examples 2:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Context: Property=Entity, Attribute=Current, Eval=LogicalName%&gt;&quot; /&gt;
</pre>
<p>will produce the following output</p>
<pre class="brush: plain; title: ; notranslate">
adx_webpage
</pre>
<p><strong>Examples 3:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Context: Property=Entity, Attribute=adx_name%&gt;&quot; /&gt;
</pre>
<p>will produce the following output</p>
<pre class="brush: plain; title: ; notranslate">Home</pre>
<p><strong>Examples 4:</strong></p>
<pre class="brush: xml; title: ; notranslate">&lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Context: Property=Website, Attribute=Current, Eval=LogicalName%&gt;&quot; /&gt;</pre>
<p>will produce the following output</p>
<pre class="brush: plain; title: ; notranslate">adx_website</pre>
<p><strong>Examples 5:</strong></p>
<pre class="brush: xml; title: ; notranslate"> &lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Context: Property=Website, Attribute=adx_name%&gt;&quot; /&gt; </pre>
<p>will produce the following output</p>
<pre class="brush: plain; title: ; notranslate">Cusomer Portal</pre>
<p><strong>CurrentContact Expression</strong></p>
<p>CurrentContact Expression is a shortcut of PortalContext Expression with Property set to <strong>User</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;%$ Context: Property=User, Attribute=attribute, Eval=eval, Format=format, Default=default, Portal=portal%&gt;
&lt;%$ Context: User, attribute, eval, format, default, portal%&gt; </pre>
<p><strong>Website Expression</strong></p>
<p>Website Expression is a shortcut of PortalContext Expression with Property set to <strong>Website</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;%$ Context: Property=Website, Attribute=attribute, Eval=eval, Format=format, Default=default, Portal=portal%&gt;
&lt;%$ Context: Website, attribute, eval, format, default, portal%&gt; </pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=256&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/04/dynamics-crm-2011-portal-development-portalcontex-expression/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development &#8211; CrmSiteMap Expression</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/03/dynamics-crm-2011-portal-development-crsitemap-expression/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/03/dynamics-crm-2011-portal-development-crsitemap-expression/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 13:50:49 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=237</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development CrmSiteMap expression More information regarding to ASP.NET Site Maps and SiteMapProvider Class CrmSiteMap expression require ASP.NET sitemap feature enabled and Microsoft.Xrm.Portal.Web.CrmSiteMapProvider to be the default sitemap provider. CrmSiteMapProvider use Site Marker entity (adx_sitemarker) contained in portalbase &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/03/dynamics-crm-2011-portal-development-crsitemap-expression/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=237&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p><strong>CrmSiteMap expression</strong></p>
<p>More information regarding to <a title="ASP.NET Site Maps" href="http://msdn.microsoft.com/en-us/library/yy2ykkab(v=vs.110).aspx">ASP.NET Site Maps</a> and <a title="SiteMapProvider Class" href="http://msdn.microsoft.com/en-us/library/e52te4hd(v=vs.110).aspx">SiteMapProvider Class</a></p>
<p>CrmSiteMap expression require ASP.NET sitemap feature enabled and Microsoft.Xrm.Portal.Web.CrmSiteMapProvider to be the default sitemap provider. CrmSiteMapProvider use Site Marker entity (adx_sitemarker) contained in portalbase solution as persistent store.This can be set up in web.config</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;configuration&gt;
	&lt;system.web&gt;
		&lt;siteMap enabled=&quot;true&quot; defaultProvider=&quot;Crm&quot;&gt;
			&lt;providers&gt;
				&lt;clear/&gt;
				&lt;add name=&quot;Crm&quot; type=&quot;Microsoft.Xrm.Portal.Web.CrmSiteMapProvider, Microsoft.Xrm.Portal&quot; securityTrimmingEnabled=&quot;true&quot;/&gt;
			&lt;/providers&gt;
		&lt;/siteMap&gt;
	&lt;system.web&gt;
&lt;configuration&gt;
</pre>
<p>Syntax:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%$ CrmSiteMap: SiteMarker=siteMarker, Return=return, Eval=eval, Format=format, Portal=portal%&gt;
&lt;%$ CrmSiteMap: siteMarker, return, eval, format, portal%&gt;
</pre>
<p>Snippet Expression takes a format of comma separated name value pairs, any pair is optional and the name of the pair is optional as well. If name is omitted, then the sequence is significant.</p>
<p>The first name value pair (<strong>SiteMarker</strong>) is the value of Name attribute (adx_name) of Site Marker entity (adx_sitemarker) contained in portalbase solution.</p>
<p>One instance of CrmSiteMapNode will be created for the rest of expression evaluation.</p>
<p>CrmSiteMapNode contains four more extra properties than base ASP.NET SiteMapNode object: Entity, LastModified, RewriteUrl and StatusCode. The entity will be the Web Page (adx_webpage) entity instance related to the Site Marker entity (adx_sitemarker) with the name specified.</p>
<p>The Web Page (adx_webpage) entity will be retrieved from CRM first, and the Partial Url (adx_partialurl) attribute value will be used to find CrmSiteMapNode within sitemap. If <strong>special value &#8220;Current&#8221;</strong> is specified, the current web page path will be used to find CrmSiteMapNode within sitemap.</p>
<p>CrmSiteMapProvider use Site Marker entity (adx_sitemarker) contained in portalbase solution as persistent store. SiteMap is defined as a view of Site Marker entity for the specified web site. If the partial url/web page path from the previous description is found in this list of Site Marker entities. A corresponding CrmSiteMapNode will be created otherwise one CrmSiteMapNode instance with &#8220;Page Not Found&#8221; Site Marker will be created. If &#8220;Page Not Found&#8221; Site Marker does not exist in CRM, null will be returned.</p>
<p>The second name value pair (<strong>Return</strong>) can be set to either &#8220;<strong>Entity</strong>&#8221; or &#8220;<strong>Url</strong>&#8220;, if it is not specified the value of Eval and Format will determine the expression value, if any other value is specified an instance of CrmSiteMapNode will be returned.</p>
<p>If it is set to &#8220;Entity&#8221;, the value of the expression will be the Web Page (adx_webpage) entity instance related to the Site Marker entity (adx_sitemarker) with the name specified for the first name value pair.</p>
<p>If it is set to &#8220;Url&#8221;, the value of the expression will be the Partial Url (adx_partialurl) attribute value of the Web Page (adx_webpage) entity instance related to the Site Marker entity (adx_sitemarker) with the name specified for the first name value pair.</p>
<p>If we have the following web page created within CRM (Name=&#8221;View Scheduled Services&#8221; Partial Url=&#8221;view-scheduled-services&#8221;)<br />
<a href="http://zhongchenzhou.files.wordpress.com/2012/04/page.jpg"><img title="page" src="http://zhongchenzhou.files.wordpress.com/2012/04/page.jpg?w=300&#038;h=46" alt="" width="300" height="46" /></a><br />
the following Site Marker created within CRM which related to the previous web page (Name=&#8221;View Scheduled Services&#8221; Page=&#8221;View Scheduled Services&#8221;)<br />
<a href="http://zhongchenzhou.files.wordpress.com/2012/04/sitemarker.jpg"><img class="alignnone size-medium wp-image-241" title="sitemarker" src="http://zhongchenzhou.files.wordpress.com/2012/04/sitemarker.jpg?w=300&#038;h=42" alt="" width="300" height="42" /></a><br />
The following expression</p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Literal ID=&quot;Literal1&quot; runat=&quot;server&quot; Text=&quot;&lt;%$ CrmSiteMap: SiteMarker=View Scheduled Services, Return=Entity%&gt;&quot; /&gt;
</pre>
<p>will produce the following error, this verify that the value of the CrmSiteMap expression is an Entity with logical name &#8220;adx_webpage&#8221;<br />
<a href="http://zhongchenzhou.files.wordpress.com/2012/04/returnentity.jpg"><img class="alignnone size-medium wp-image-242" title="returnentity" src="http://zhongchenzhou.files.wordpress.com/2012/04/returnentity.jpg?w=300&#038;h=187" alt="" width="300" height="187" /></a><br />
The following CrmSiteMap expression will be evaluated to &#8220;/view-scheduled-services&#8221;</p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Literal ID=&quot;Literal1&quot; runat=&quot;server&quot; Text=&quot;&lt;%$ CrmSiteMap: SiteMarker=View Scheduled Services, Return=Url%&gt;&quot; /&gt;
</pre>
<p>The third and fourth name value pair (<strong>Eval</strong> &amp; <strong>Format</strong>) will only be taken into consideration when second name value pair (<strong>Return</strong>) is not specified. The value then will  be passed as parameters to System.Web.UI.DataBinder.Eval(CrmSiteMapNode, eval, format) and the value is substituted for the expression syntax when the second name value pair is not specified.</p>
<p>The following expression will product &#8220;Partial Url is: /view-scheduled-services&#8221;</p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Literal ID=&quot;Literal1&quot; runat=&quot;server&quot; Text=&quot;&lt;%$ CrmSiteMap: SiteMarker=View Scheduled Services, Eval=Url, Format=Partial Url is {0}%&gt;&quot; /&gt;
</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=237&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/03/dynamics-crm-2011-portal-development-crsitemap-expression/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/page.jpg?w=300" medium="image">
			<media:title type="html">page</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/sitemarker.jpg?w=300" medium="image">
			<media:title type="html">sitemarker</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/returnentity.jpg?w=300" medium="image">
			<media:title type="html">returnentity</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development &#8211; Getting Started</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-hello-world/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-hello-world/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 12:51:59 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=206</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development Getting Started 1. Import solution from sdk\Solutions\PortalBase\MicrosoftXrmPortals_managed.zip. Detailed steps can be found Install the Base Portal Solution The following navigation will be available in crm after import portal base solution 2. Create a new website, set the &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-hello-world/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=206&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p><strong>Getting Started</strong></p>
<p>1. Import solution from sdk\Solutions\PortalBase\MicrosoftXrmPortals_managed.zip. Detailed steps can be found <a href="http://msdn.microsoft.com/en-us/library/gg695813.aspx#install" target="_blank">Install the Base Portal Solution</a></p>
<p>The following navigation will be available in crm after import portal base solution</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/navigation.jpg"><img class="alignnone size-medium wp-image-212" title="navigation" src="http://zhongchenzhou.files.wordpress.com/2012/04/navigation.jpg?w=107&#038;h=300" alt="" width="107" height="300" /></a></p>
<p>2. Create a new website, set the <strong>name </strong>of the website to &#8220;<strong>Hello World Portal</strong>&#8220;</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/website.jpg"><img class="alignnone size-medium wp-image-213" title="website" src="http://zhongchenzhou.files.wordpress.com/2012/04/website.jpg?w=300&#038;h=40" alt="" width="300" height="40" /></a></p>
<p>3. create a new Content Snippet, set the <strong>name </strong>of the snippet to &#8220;<strong>HelloWorld</strong>&#8220;, <strong>value </strong>to &#8220;<strong>Hello World!!!</strong>&#8220;</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/snippet.jpg"><img class="alignnone size-medium wp-image-214" title="snippet" src="http://zhongchenzhou.files.wordpress.com/2012/04/snippet.jpg?w=300&#038;h=83" alt="" width="300" height="83" /></a></p>
<p>4. Create a new empty web application in Visual Studio</p>
<p>5. Add reference to <strong>microsoft.xrm.client</strong> and <strong>microsoft.xrm.portal</strong> in sdk\bin\</p>
<p>6. Replace web.config with the following, <strong>change connectionString value</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;configuration&gt;
    &lt;configSections&gt;
        &lt;section name=&quot;microsoft.xrm.client&quot; type=&quot;Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client&quot;/&gt;
        &lt;section name=&quot;microsoft.xrm.portal&quot; type=&quot;Microsoft.Xrm.Portal.Configuration.PortalCrmSection, Microsoft.Xrm.Portal&quot;/&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
        &lt;add name=&quot;Xrm&quot; connectionString=&quot;ServiceUri=http://win-b1dmdctdenr/ :5555/Cleanup;&quot;/&gt;
    &lt;/connectionStrings&gt;
    &lt;system.web&gt;
        &lt;compilation debug=&quot;true&quot; targetFramework=&quot;4.0&quot;&gt;
            &lt;expressionBuilders&gt;
                &lt;add expressionPrefix=&quot;Snippet&quot; type=&quot;Microsoft.Xrm.Portal.Web.Compilation.SnippetExpressionBuilder, Microsoft.Xrm.Portal&quot;/&gt;
            &lt;/expressionBuilders&gt;
        &lt;/compilation&gt;
    &lt;/system.web&gt;
    &lt;microsoft.xrm.client&gt;
        &lt;contexts&gt;
            &lt;add name=&quot;Xrm&quot; type=&quot;Microsoft.Xrm.Client.CrmOrganizationServiceContext, Microsoft.Xrm.Client&quot;/&gt;
        &lt;/contexts&gt;
    &lt;/microsoft.xrm.client&gt;
    &lt;microsoft.xrm.portal&gt;
        &lt;portals&gt;
            &lt;add name=&quot;Hello World Portal&quot;/&gt;
        &lt;/portals&gt;
    &lt;/microsoft.xrm.portal&gt;
&lt;/configuration&gt;
</pre>
<p>7. Add HelloWorld.aspx to the project and set as start page</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;HelloWorld.aspx.cs&quot; Inherits=&quot;HelloWorldPortal.HelloWorld&quot; %&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd &quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml &quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
        &lt;h1&gt;&lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Snippet: HelloWorld %&gt;&quot; /&gt;&lt;/h1&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>8. Debug web application, check result.</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/result.jpg"><img class="alignnone size-medium wp-image-215" title="result" src="http://zhongchenzhou.files.wordpress.com/2012/04/result.jpg?w=300&#038;h=44" alt="" width="300" height="44" /></a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=206&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-hello-world/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/navigation.jpg?w=107" medium="image">
			<media:title type="html">navigation</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/website.jpg?w=300" medium="image">
			<media:title type="html">website</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/snippet.jpg?w=300" medium="image">
			<media:title type="html">snippet</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/result.jpg?w=300" medium="image">
			<media:title type="html">result</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamics CRM 2011 Portal Development &#8211; Snippet/SiteSetting Expression</title>
		<link>http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-asp-net-expressions/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-asp-net-expressions/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 05:00:49 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=200</guid>
		<description><![CDATA[Dynamics CRM 2011 Portal Development Snippet Expression More information regarding to ASP.NET expression can be found ASP.NET Expressions Overview  and ExpressionBuilder Class. There are 7 expression builders contained in microsoft.xrm.portal.dll assembly. CrmSiteMapExpressionBuilder CurrentContactExpressionBuilder PortalContextExpressionBuilder SiteSettingExpressionBuilder SnippetExpressionBuilder TimeZoneExpressionBuilder WebsiteExpressionBuilder Expression builders need to be &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-asp-net-expressions/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=200&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a title="Dynamics CRM 2011 Portal Development" href="http://zhongchenzhou.wordpress.com/2012/04/05/dynamics-crm-2011-portal-development/" target="_blank">Dynamics CRM 2011 Portal Development</a></p>
<p><strong>Snippet Expression</strong></p>
<p>More information regarding to ASP.NET expression can be found <a title="ASP.NET Expressions Overview" href="http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx" target="_blank">ASP.NET Expressions Overview</a>  and <a title="ExpressionBuilder Class" href="http://msdn.microsoft.com/en-us/library/system.web.compilation.expressionbuilder.aspx" target="_blank">ExpressionBuilder Class</a>.</p>
<p>There are 7 expression builders contained in microsoft.xrm.portal.dll assembly.</p>
<ul>
<li>CrmSiteMapExpressionBuilder</li>
<li>CurrentContactExpressionBuilder</li>
<li>PortalContextExpressionBuilder</li>
<li>SiteSettingExpressionBuilder</li>
<li>SnippetExpressionBuilder</li>
<li>TimeZoneExpressionBuilder</li>
<li>WebsiteExpressionBuilder</li>
</ul>
<p>Expression builders need to be registered in web.config<strong><span style="font-size:14px;"><br />
</span></strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;compilation debug=&quot;true&quot; targetFramework=&quot;4.0&quot;&gt;
            &lt;expressionBuilders&gt;
                &lt;add expressionPrefix=&quot;Snippet&quot; type=&quot;Microsoft.Xrm.Portal.Web.Compilation.SnippetExpressionBuilder, Microsoft.Xrm.Portal&quot;/&gt;
                &lt;add expressionPrefix=&quot;SiteSetting&quot; type=&quot;Microsoft.Xrm.Portal.Web.Compilation.SiteSettingExpressionBuilder, Microsoft.Xrm.Portal&quot;/&gt;
                &lt;add expressionPrefix=&quot;CrmSiteMap&quot; type=&quot;Microsoft.Xrm.Portal.Web.Compilation.CrmSiteMapExpressionBuilder, Microsoft.Xrm.Portal&quot;/&gt;
                &lt;add expressionPrefix=&quot;Context&quot; type=&quot;Microsoft.Xrm.Portal.Web.Compilation.PortalContextExpressionBuilder, Microsoft.Xrm.Portal&quot;/&gt;
            &lt;/expressionBuilders&gt;
        &lt;/compilation&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;
</pre>
<p><strong><span style="font-size:14px;"><br />
Snippet Expression</span></strong></p>
<p>Snippet Expression evaluated to Value attribute (adx_value) of Content Snippet entity instance (adx_contentsnippet) contained in portalbase solution.</p>
<p>Syntax:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%$ Snippet: Name=somename, Default=defaultvalue, Format=stringformat, Portal=someportal %&gt;
&lt;%$ Snippet: somename, defaultvalue, stringformat, someportal %&gt;
</pre>
<p>Snippet Expression takes a format of comma separated name value pairs, any pair is optional and the name of the pair is optional as well. If name is omitted, then the sequence is significant.</p>
<p>The first name value pair (<strong>Name</strong>) is the value of Name attribute (adx_name) of Content Snippet entity (adx_contentsnippet) contained in portalbase solution. The value of the expression will be evaluated as the value of Value attribute (adx_value) of the same entity instance.</p>
<p>The second name value pair (<strong>Default</strong>) is the value to be taken for the result of the expression evaluation if an instance of Content Snippet entity (adx_contentsnippet) with the specified Name attribute (adx_name) does not exist for the portal in the connected Microsoft Dynamics CRM 2011 instance.</p>
<p>The third name value pair (<strong>Format</strong>) is going to be passed as a parameter to string.Format(format,  adx_value) and the value is substituted for the expression syntax.</p>
<p>The fourth name value pair (<strong>Portal</strong>) is checked against configured portals in the web.config file and used to create IPortalContext instance</p>
<pre class="brush: xml; title: ; notranslate">
&lt;microsoft.xrm.portal&gt;
    &lt;portals&gt;
        &lt;add name=&quot;Customer Portal&quot;/&gt;
    &lt;/portals&gt;
&lt;/microsoft.xrm.portal&gt;
</pre>
<p>This value should be the value of Name attribute (adx_name) of Website entity (adx_website) contained in portalbase solution.</p>
<p>Assume we have the following website created in CRM</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/websites.jpg"><img class="alignnone size-medium wp-image-218" title="websites" src="http://zhongchenzhou.files.wordpress.com/2012/04/websites.jpg?w=300&#038;h=61" alt="" width="300" height="61" /></a></p>
<p>two different snippets created in each website</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/snippets.jpg"><img class="alignnone size-medium wp-image-219" title="snippets" src="http://zhongchenzhou.files.wordpress.com/2012/04/snippets.jpg?w=300&#038;h=39" alt="" width="300" height="39" /></a></p>
<p>two portals configured in web.config for each website inside CRM</p>
<pre class="brush: xml; title: ; notranslate">
&lt;microsoft.xrm.portal&gt;
    &lt;portals&gt;
        &lt;add name=&quot;Customer Portal&quot;/&gt;
        &lt;add name=&quot;Test Portal&quot;/&gt;
    &lt;/portals&gt;
&lt;/microsoft.xrm.portal&gt;
</pre>
<p>The following expression</p>
<pre class="brush: xml; title: ; notranslate">
&lt;table&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;Name&lt;/th&gt;
                &lt;th&gt;Default&lt;/th&gt;
                &lt;th&gt;Format&lt;/th&gt;
                &lt;th&gt;Portal&lt;/th&gt;
                &lt;th&gt;Value&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
                &lt;td&gt;Custom Snippet A&lt;/td&gt;
                &lt;td&gt;defaultA&lt;/td&gt;
                &lt;td&gt;Value: {0}&lt;/td&gt;
                &lt;td&gt;Customer Portal&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Snippet: Name=Custom Snippet A, Default=defaultA, Format=Value: {0}, Portal=Customer Portal %&gt;&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;Custom Snippet A&lt;/td&gt;
                &lt;td&gt;defaultA&lt;/td&gt;
                &lt;td&gt;Value: {0}&lt;/td&gt;
                &lt;td&gt;Test Portal&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Snippet: Name=Custom Snippet A, Default=defaultA, Format=Value: {0}, Portal=Test Portal %&gt;&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;Test Snippet B&lt;/td&gt;
                &lt;td&gt;defaultB&lt;/td&gt;
                &lt;td&gt;Value: {0}&lt;/td&gt;
                &lt;td&gt;Customer Portal&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Snippet: Name=Test Snippet B, Default=defaultB, Format=Value: {0}, Portal=Customer Portal %&gt;&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;Test Snippet B&lt;/td&gt;
                &lt;td&gt;defaultB&lt;/td&gt;
                &lt;td&gt;Value: {0}&lt;/td&gt;
                &lt;td&gt;Test Portal&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:Literal runat=&quot;server&quot; Text=&quot;&lt;%$ Snippet: Name=Test Snippet B, Default=defaultB, Format=Value: {0}, Portal=Test Portal %&gt;&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
</pre>
<p>will produce the result</p>
<p><a href="http://zhongchenzhou.files.wordpress.com/2012/04/result1.jpg"><img class="alignnone size-medium wp-image-220" title="result" src="http://zhongchenzhou.files.wordpress.com/2012/04/result1.jpg?w=300&#038;h=123" alt="" width="300" height="123" /></a></p>
<p><strong>SiteSetting Expression</strong></p>
<p>SiteSetting Expression works the same way as Snippet Expression. It takes the same 4 name and value pairs but read value from <strong>Site Settings (adx_sitesetting)</strong> entity contained in portalbase solution</p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=200&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/04/02/getting-started-for-microsoft-dynamics-crm-2011-portal-asp-net-expressions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/websites.jpg?w=300" medium="image">
			<media:title type="html">websites</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/snippets.jpg?w=300" medium="image">
			<media:title type="html">snippets</media:title>
		</media:content>

		<media:content url="http://zhongchenzhou.files.wordpress.com/2012/04/result1.jpg?w=300" medium="image">
			<media:title type="html">result</media:title>
		</media:content>
	</item>
		<item>
		<title>HTTP Summary</title>
		<link>http://zhongchenzhou.wordpress.com/2012/02/09/http-summary/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/02/09/http-summary/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 08:50:03 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTTP]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=166</guid>
		<description><![CDATA[HTTP Request Methods: GET POST PUT DELETE HEAD TRACE OPTIONS CONNECT HTTP Request Headers: Accept Accept-Charset Accept-Encoding Accept-Language Authorization Cookie Expect From Host If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since Max-Forwards Proxy-Authorization Range Referer TE User-Agent HTTP Response Status Codes Informational (100-199) &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/02/09/http-summary/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=166&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h2>HTTP Request Methods:</h2>
<p>GET<br />
POST<br />
PUT<br />
DELETE<br />
HEAD<br />
TRACE<br />
OPTIONS<br />
CONNECT</p>
<h2>HTTP Request Headers:</h2>
<p>Accept<br />
Accept-Charset<br />
Accept-Encoding<br />
Accept-Language<br />
Authorization<br />
Cookie<br />
Expect<br />
From<br />
Host<br />
If-Match<br />
If-Modified-Since<br />
If-None-Match<br />
If-Range<br />
If-Unmodified-Since<br />
Max-Forwards<br />
Proxy-Authorization<br />
Range<br />
Referer<br />
TE<br />
User-Agent</p>
<h2>HTTP Response Status Codes</h2>
<p>Informational (100-199)<br />
Successful (200-299)<br />
Redirection (300-399)<br />
Client error (400-499)<br />
Server error (500-599)</p>
<p>100 Continue<br />
101 Switching Protocols</p>
<p>200 OK<br />
201 Created<br />
202 Accepted<br />
203 Non-Authoritative Information<br />
204 No Content<br />
205 Reset Content<br />
206 Partial Content</p>
<p>300 Multiple Choices<br />
301 Moved Permanently<br />
302 Found<br />
303 See Other (302 Found | Get)<br />
304 Not Modified<br />
305 Use Proxy<br />
306 * Deprecated *<br />
307 Temporary Redirect (302 Found | same request method)</p>
<p>400 Bad Request<br />
401 Unauthorized<br />
402 Payment Required<br />
403 Forbidden<br />
404 Not Found<br />
405 Method Not Allowed<br />
406 Not Acceptable<br />
407 Proxy Authentication Required<br />
408 Request Timeout<br />
409 Conflict<br />
410 Gone<br />
411 Length Required<br />
412 Precondition Failed<br />
413 Request Entity Too Large<br />
414 Request-URI Too Long<br />
415 Unsupported Media Type<br />
416 Requested Range Not Satisfiable<br />
417 Expectation Failed</p>
<p>500 Internal Server Error<br />
501 Not Implemented<br />
502 Bad Gateway<br />
503 Service Unavailable<br />
504 Gateway Timeout<br />
505 HTTP Version Not Supported</p>
<h2>HTTP Response Headers</h2>
<p>Accept-Ranges (bytes | none)<br />
Age<br />
Authentication-Info (HTTP digest authentication)<br />
Content-Disposition (suggested filename)<br />
ETag<br />
Location<br />
Proxy-Authenticate<br />
Refresh (meta http-equiv=&#8221;refresh&#8221; content=&#8221;3; url=http://httphandbook.org/&#8221;)<br />
Retry-After (503 or any of the 300-range (redirection) status codes)<br />
Server<br />
Set-Cookie<br />
Vary (cache proxy)<br />
WWW-Authenticate</p>
<h2>HTTP General Headers</h2>
<ul>
<li><strong>Cache-Control</strong></li>
</ul>
<pre class="brush: plain; title: ; notranslate">
HTTP Request
	no-cache (do not cache http headers specified)
	no-store (do not cache current http request &amp; response)
	max-age
	max-stale (extend expiration date of the resource for the purpose of caching)
	min-fresh (reduce expiration date of the resource for the purpose of caching)
	no-transform (do not modify the content part of the HTTP response)
	only-if-cached (do not contact server, send cache back to client)
	cache-extension (specify not explicitly defined directives)
HTTP Response
	public (any caching by any caching system)
	private (allows caching, but not on shared caches | browser cache is private)
	no-cache
	no-store
	no-transform
	must-revalidate (must revalidate after expired)
	proxy-revalidate (must-revalidate exclude private caches)
	max-age
	s-maxage (max-age exclude private caches)
	cache-extension
</pre>
<ul>
<li><strong>Connection</strong> (HTTP connection management | TCP)(Keep-Alive | Close | Upgrade)</li>
<li><strong>Date</strong> (system time when request was generated on Browser or response was generated on Server)</li>
<li><strong>Pragma</strong> (caching in HTTP/1.0) (Pragma: no-cache) (forward request or response to server or browser)</li>
<li><strong>Keep-Alive</strong> (maximum amount of time that the TCP connection can remain open) (require Connection general header have a value of Keep-Alive)</li>
<li><strong>Trailer</strong> (include some HTTP headers after the content) (require Transfer-Encoding: chunked)</li>
<li><strong>Transfer-Encoding</strong> (each piece of the content begins with a hexadecimal value of the length of the next chunk on a line by itself)</li>
<li><strong>Upgrade</strong> (negotiate a change in protocol)</li>
<li><strong>Via</strong> (proxies add their name to &#8220;Via&#8221; header as they forward messages)</li>
<li><strong>Warning</strong></li>
</ul>
<pre class="brush: plain; title: ; notranslate">
	110 Response is stale
	111 Revalidation failed
	112 Disconnected operation
	113 Heuristic expiration
	199 Miscellaneous warning
	214 Transformation applied
	299 Miscellaneous persistent warning
</pre>
<h2>HTTP Entity Headers</h2>
<p>Allow<br />
Content-Encoding (compress | deflate | gzip)<br />
Content-Language<br />
Content-Length (the length of the content section of the HTTP message in bytes)<br />
Content-Location (the URL of the resource being returned differs from the URL being requested)<br />
Content-MD5 (MD5 &amp;&amp; Base-64 encoding)<br />
Content-Range (Content-Range: 600-900/1234)<br />
Content-Type (Content-Type: text/html)<br />
Expires<br />
Last-Modified</p>
<h2>HTTP Formatting Specifications</h2>
<p><strong>Line Termination</strong>: CRLT (carriage return plus a line feed, \r\n)<br />
<strong>Content Separation</strong>: empty line<br />
<strong>Header Formatting</strong>: Header-Name: value<br />
<strong>Date Formats</strong>: Tue, 21 May 2002 12:34:56 GMT<br />
<strong>URL Encoding</strong>: ISO-Latin characters 32-126, Reserved characters is encoded as a percent sign (%), followed by the hexadecimal value of the character<br />
<strong>HTML entities</strong>: is encoded as &#8220;<strong>&amp;#xxx;</strong>&#8221; where <strong>xxx</strong> represents the decimal value of the character (&#8220;&amp; a m p ;&#8221; is an ampersand)</p>
<h2>HTTP Media Types</h2>
<ul>
<li>application</li>
<li>audio</li>
<li>image</li>
<li>message</li>
<li>model</li>
<li>multipart</li>
<li>text</li>
<li>video</li>
</ul>
<p>The most current list of all registered media types can be found at <a href="http://www.iana.org/assignments/media-types/index.html" target="_blank">http://www.iana.org/assignments/media-types/index.html</a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/http/'>HTTP</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=166&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/02/09/http-summary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Enable or Disable XAML Workflows in Dynamics CRM 2011</title>
		<link>http://zhongchenzhou.wordpress.com/2012/01/25/enable-or-disable-xaml-workflows-in-dynamics-crm-2011/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/01/25/enable-or-disable-xaml-workflows-in-dynamics-crm-2011/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 12:56:00 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[Microsoft Dynamics CRM]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=154</guid>
		<description><![CDATA[Filed under: Microsoft Dynamics CRM Tagged: Microsoft Dynamics CRM<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=154&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: sql; title: ; notranslate">
UPDATE MSCRM_CONFIG..ServerSettingsProperties
   SET BitColumn = 1
 WHERE ColumnName = 'AllowDeclarativeWorkflows'
</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/microsoft-dynamics-crm/'>Microsoft Dynamics CRM</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=154&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/01/25/enable-or-disable-xaml-workflows-in-dynamics-crm-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>Debug latest JavaScript in browser</title>
		<link>http://zhongchenzhou.wordpress.com/2012/01/22/debug-latest-javascript-in-browser/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/01/22/debug-latest-javascript-in-browser/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 02:43:45 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=151</guid>
		<description><![CDATA[IE: Internet Options &#8211;&#62; Advanced &#8211;&#62; Browsing &#8211;&#62; &#8220;Disable script debugging (Internet Explorer)&#8221; = OFF Internet Options &#8211;&#62; Advanced &#8211;&#62; Browsing &#8211;&#62; &#8220;Disable script debugging (Other)&#8221; = OFF Internet Options &#8211;&#62; Advanced &#8211;&#62; Browsing &#8211;&#62; &#8220;Show friendly HTTP error messages&#8221; &#8230; <a href="http://zhongchenzhou.wordpress.com/2012/01/22/debug-latest-javascript-in-browser/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=151&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong>IE:</strong></p>
<p>Internet Options &#8211;&gt; Advanced &#8211;&gt; Browsing &#8211;&gt; &#8220;Disable script debugging (Internet Explorer)&#8221; = OFF<br />
Internet Options &#8211;&gt; Advanced &#8211;&gt; Browsing &#8211;&gt; &#8220;Disable script debugging (Other)&#8221; = OFF<br />
Internet Options &#8211;&gt; Advanced &#8211;&gt; Browsing &#8211;&gt; &#8220;Show friendly HTTP error messages&#8221; = OFF<br />
Internet Options &#8211;&gt; General&#8211;&gt; Browsing history &#8211;&gt; Settings &#8211;&gt; Check for newer versions of stored pages: == &#8220;Every time I visit the webpage&#8221;</p>
<p><strong>Clear cache</strong><br />
Internet Options &#8211;&gt; General&#8211;&gt; Browsing history &#8211;&gt; Delete&#8230; &#8211;&gt;<br />
Uncheck &#8220;Preserve Favorites website data&#8221;<br />
Check &#8220;Temporary Internet files&#8221; &#8220;Cookies&#8221;<br />
&#8211;&gt; Delete</p>
<p><strong>Dynamics CRM:</strong><br />
Set the DevErrors attribute to On in the Web.config file.</p>
<p><strong>Firefox:</strong></p>
<p>visit about:config, find the browser.cache.check_doc_frequency and change it to 1.</p>
<p>0 – Check for a new version of a page once per session (a session starts when the first application window opens and ends when the last application window closes).</p>
<p>1 &#8211; Check for a new version every time a page is loaded.</p>
<p>2 – Never check for a new version – always load the page from cache.</p>
<p>3- Check for a new version when the page is out of date. (Default)</p>
<p><a href="http://www.imasuper.com/53/technology/firefox-caching-get-latest-page-every-time/">http://www.imasuper.com/53/technology/firefox-caching-get-latest-page-every-time</a></p>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/javascript/'>JavaScript</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=151&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/01/22/debug-latest-javascript-in-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Magento WS-I compliant v2 API</title>
		<link>http://zhongchenzhou.wordpress.com/2012/01/15/how-to-use-magento-ws-i-compliant-v2-api/</link>
		<comments>http://zhongchenzhou.wordpress.com/2012/01/15/how-to-use-magento-ws-i-compliant-v2-api/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 10:53:51 +0000</pubDate>
		<dc:creator>Zhongchen Zhou</dc:creator>
				<category><![CDATA[eCommerce]]></category>
		<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://zhongchenzhou.wordpress.com/?p=141</guid>
		<description><![CDATA[Filed under: eCommerce Tagged: Magento<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=141&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: php; title: ; notranslate">
$proxy = new SoapClient('http://127.0.0.1/Magento1620/index.php/api/v2_soap?wsdl', array('trace' =&gt; 1, 'connection_timeout' =&gt; 120));

	$session = $proxy-&gt;login(array(
			'username' =&gt; &quot;xxyyzz&quot;,
			'apiKey' =&gt; &quot;xxyyzz&quot;
			));
	
	$sessionId = $session-&gt;result;
	
	$filters = array(
			'complex_filter' =&gt; array(
					array(
							'key' =&gt; 'product_id',
							'value' =&gt; array(
									'key' =&gt; 'eq',
									'value' =&gt; '18'
									)
							)
					)
			);
	
	$products = $proxy-&gt;catalogProductList(array(&quot;sessionId&quot; =&gt; $sessionId, &quot;filters&quot; =&gt; $filters));
</pre>
<br />Filed under: <a href='http://zhongchenzhou.wordpress.com/category/ecommerce/'>eCommerce</a> Tagged: <a href='http://zhongchenzhou.wordpress.com/tag/magento/'>Magento</a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zhongchenzhou.wordpress.com&#038;blog=23858672&#038;post=141&#038;subd=zhongchenzhou&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zhongchenzhou.wordpress.com/2012/01/15/how-to-use-magento-ws-i-compliant-v2-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a53a6a1fa330d23cd02a82cf4a3d31b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zhongchenzhou</media:title>
		</media:content>
	</item>
	</channel>
</rss>
