<?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/"
	>

<channel>
	<title>From the Stone Age to xRM.....</title>
	<atom:link href="http://blog.xrm-services.co.uk/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.xrm-services.co.uk</link>
	<description>xRM4.0, xRM 2011</description>
	<lastBuildDate>Wed, 27 Feb 2013 05:27:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Explaining Data Migration &amp; Data Integration to&#8230;The Wife</title>
		<link>http://blog.xrm-services.co.uk/?p=225</link>
		<comments>http://blog.xrm-services.co.uk/?p=225#comments</comments>
		<pubDate>Wed, 27 Feb 2013 04:37:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=225</guid>
		<description><![CDATA[Data migration and data integration are one of those subject that you either love or hate – the Marmite (Vegimite)&#160; syndrome . I’m one of those people who love it. Whilst working on a project that required both, I tried &#8230; <a href="http://blog.xrm-services.co.uk/?p=225">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Data migration and data integration are one of those subject that you either love or hate – the Marmite (Vegimite)&nbsp; syndrome . I’m one of those people who love it.</p>
<p>Whilst working on a project that required both, I tried to explain the process to my wife – ‘cos she asked. As I went into the intricacies of staging and transformations, scheduled process etc.. I noticed I had lost her at the staging database – the clue was she was on facebook!</p>
<p>So, rewinding, I started again – using CRM, data migration terms and a real world example:</p>
<p><strong>The Objective</strong></p>
<p>We are on a family holiday for 2 weeks, beach , sun, self-catering etc…We take suitcases full of clothes. The usual holiday approach of we take too much, clothes we won’t use, clothes we think we will need and the pair of shorts you live and die in.</p>
<p>When we get home , my daughter and I would like to find our clothes washed , ironed and placed in the correct room, wardrobe, chest of drawer and draw.</p>
<p><strong>The Client.</strong></p>
<p>My daughter and me!.</p>
<p><strong>Disparate Data sources.</strong></p>
<p>On arriving home, neither myself or my daughter have any interest in the “laundry” cycle. We just assume there is a laundry fairy that makes things happen. So, as suitcases get emptied, piles of clothes appear – general in the same location of the opening of the suitcase.</p>
<p><strong>Staging Database.</strong></p>
<p>My wife will collect all the piles of laundry and move these many piles to one big pile in the utility room. </p>
<p><strong>Cleansing &amp; De-Duplication.</strong></p>
<p>From the big pile , she will sort the big pile into various smaller piles based on colour, material etc.. These piles enter the washing machine. The washing cycle takes a few hours and can only take the sorted pile of laundry of the same colour and type.</p>
<p><strong>Scope Creep.</strong></p>
<p>My daughter , in boredom mode from returning from a fun filled holiday, finds the PE bag in the corner of the room with 2 week old kit which she forgot about. This is mainly due to the excitement of the impending holiday. So, she dutifully bring the previously unknown bag of laundry down to the utility and dumps it in the middle of the other segmented piles of laundry.</p>
<p>The usual discussion happens along the lines of “Why didn’t you mention this earlier”, “I didn’t think it would matter”.</p>
<p><strong>The effect of scope creep.</strong></p>
<p>My wife, now has to sort the new bag of laundry and assess whether each item can be added to the existing pile or a new pile should be started. In some instances the new pile is not viable for a full load in the washing machine so she will make the decision to defer that pile for another week.</p>
<p>The net result of the sudden appearance of the PE kit is Dinner will be late “or go and get a take away”. The latter is more expense after a holiday.</p>
<p><strong>Deltas.</strong></p>
<p>The washing ironing cycle will take a few days to complete, largely due to the volume of clothes taken on holiday , bad planning on what was actually needed and even worse planning for the return trip when everything was thrown into the first opened suitcase.</p>
<p>However, during the weekend, we are still wearing clothes and still placing in the linen basket. Yes, we have been trained to place in the appropriate basket now instead of a pile on the floor. My wife periodically will collect the baskets content and move these to the now small piles of laundry in the utility room.</p>
<p><strong>Data Loading.</strong></p>
<p>After a few days of the weekend, the washing , iron cycle is almost complete. Clothes are clean, ironed and have now been placed in the correct wardrobe etc. As part of the housework process, my wife will match socks – so I have a pair! and throw out old socks that are no longer in use.</p>
<p><strong>The sign-off process of the bulk data load.</strong></p>
<p>In this instance, wine. As the holiday bulk washing load has been completed.</p>
<p><strong>Batch Data Integration as a scheduled task.</strong></p>
<p>The daily repetitive weekly cycle of laundry basket to utility pile to washing machine to iron to wardrobe, happens as part of our weekly routine. It just gets done, its so mundane we don’t know we are doing it because it so automated.</p>
<p><strong>On-Demand data integration.</strong></p>
<p>The usual, 6am alarm clock as I get up to visit a client in London. “Do I have a shirt ?”. I won’t complete this discussion….</p>
<p><strong>Summary.</strong></p>
<p>At the end of the “real” world example – it was clear , she had got it. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=225</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resuming a &#8220;system job&#8221;</title>
		<link>http://blog.xrm-services.co.uk/?p=224</link>
		<comments>http://blog.xrm-services.co.uk/?p=224#comments</comments>
		<pubDate>Sun, 30 Dec 2012 11:57:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=224</guid>
		<description><![CDATA[I have a requirement to force “waiting” system jobs to start and continue working.&#160; My scenario is that I have 200k records in the async queue and its stopped!. I found that resuming a job allows it to run to &#8230; <a href="http://blog.xrm-services.co.uk/?p=224">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have a requirement to force “waiting” system jobs to start and continue working.&nbsp; My scenario is that I have 200k records in the async queue and its stopped!.</p>
<p>I found that resuming a job allows it to run to completion. However, resuming too many jobs cause the job to fail.</p>
<p>My solution is to write a simple app that searching for “Waiting” jobs and resumes them. Mindful of a limit (to be discovered) that too many will cause the jobs to fail.</p>
<p>My fetch returns all the jobs:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:091861d8-bf68-4ef2-92e2-dea33ee5e3a0" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li>            <span style="color:#0000ff">string</span> fetchXml = <span style="color:#a31515">@&quot;&lt;fetch mapping=&#39;logical&#39;&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#a31515">                                    &lt;entity name=&#39;asyncoperation&#39;&gt;</span></li>
<li>    <span style="color:#a31515">                                    &lt;attribute name=&#39;asyncoperationid&#39;/&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#a31515">                                    &lt;attribute name=&#39;statecode&#39;/&gt;</span></li>
<li>    <span style="color:#a31515">                                    &lt;attribute name=&#39;statuscode&#39;/&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#a31515">                                    &lt;filter type=&#39;and&#39;&gt;</span></li>
<li>        <span style="color:#a31515">                                    &lt;condition attribute=&#39;statecode&#39; operator=&#39;eq&#39; value=&#39;1&#39;/&gt;</span></li>
<li style="background: #f3f3f3">        <span style="color:#a31515">                                    &lt;condition attribute=&#39;statuscode&#39; operator=&#39;eq&#39; value=&#39;10&#39;/&gt;</span></li>
<li>    <span style="color:#a31515">                                    &lt;/filter&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#a31515">                                    &lt;/entity&gt;</span></li>
<li>                                <span style="color:#a31515">&lt;/fetch&gt;&quot;</span>;</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>The SDK shows statecode =1 is Suspended and statuscode =10 is Waiting</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c6467067-f36f-4050-8209-6cf14308b7f7" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">EntityCollection</span>&gt; fetchedEntityCollection = curoHelper.FetchRecords(curoTenant, fetchXml);</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">EntityCollection</span> entitycollection <span style="color:#0000ff">in</span> fetchedEntityCollection)</li>
<li style="background: #f3f3f3">{</li>
<li>    <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">Entity</span> entity <span style="color:#0000ff">in</span> entitycollection.Entities)</li>
<li style="background: #f3f3f3">    {</li>
<li>        waitingJobs.Add(entity);</li>
<li style="background: #f3f3f3">    }</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>My FetchRecords using a parallel paging that will return ALL the pages, in this case about 130000 records in about 20-30 secs.</p>
<p>Now for the resume code. Simply, I need to set the statecode to Ready and the statuscode to Waiting for Resource</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:993f10e2-b440-49d8-940e-ea6ff93a9389" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li style="background: #f3f3f3"> <span style="color:#808080">///</span><span style="color:#008000"> Resume waiting jobs</span></li>
<li> <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li style="background: #f3f3f3"> <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;jobs&quot;&gt;&lt;/param&gt;</span></li>
<li> <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> ResumeJobs(<span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Entity</span>&gt; jobs)</li>
<li style="background: #f3f3f3"> {</li>
<li>     <span style="color:#008000">// Split job into 100 record blocks</span></li>
<li style="background: #f3f3f3">     <span style="color:#0000ff">int</span> blkSize = 100;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">     <span style="color:#008000">// 2 threads</span></li>
<li>     <span style="color:#2b91af">ParallelOptions</span> ops = <span style="color:#0000ff">new</span> <span style="color:#2b91af">ParallelOptions</span>();</li>
<li style="background: #f3f3f3">     ops.MaxDegreeOfParallelism = 2;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">     <span style="color:#008000">// Process 2 threads, 100 records per thread</span></li>
<li>     <span style="color:#2b91af">Parallel</span>.ForEach(<span style="color:#2b91af">Partitioner</span>.Create(0,jobs.Count,blkSize), ops, t =&gt;</li>
<li style="background: #f3f3f3">     {</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">         <span style="color:#008000">// get a block of records</span></li>
<li>         <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Entity</span>&gt; _jobs = jobs.Skip(t.Item1).Take(blkSize).ToList();</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>         <span style="color:#008000">// loop each record</span></li>
<li style="background: #f3f3f3">         <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">Entity</span> job <span style="color:#0000ff">in</span> _jobs)</li>
<li>         {</li>
<li style="background: #f3f3f3">             <span style="color:#0000ff">try</span></li>
<li>             {</li>
<li style="background: #f3f3f3">                 job[<span style="color:#a31515">&quot;statuscode&quot;</span>] = <span style="color:#0000ff">new</span> <span style="color:#2b91af">OptionSetValue</span>(0); <span style="color:#008000">// Waiting for resource</span></li>
<li>                 job[<span style="color:#a31515">&quot;statecode&quot;</span>] = <span style="color:#0000ff">new</span> <span style="color:#2b91af">OptionSetValue</span>(0); <span style="color:#008000">//Ready</span></li>
<li style="background: #f3f3f3">                 </li>
<li>                 <span style="color:#008000">// update</span></li>
<li style="background: #f3f3f3">                 curoHelper.CrmHelper.Update(job, throwException);</li>
<li>             }</li>
<li style="background: #f3f3f3">             <span style="color:#0000ff">catch</span> (<span style="color:#2b91af">Exception</span> ex)</li>
<li>             {</li>
<li style="background: #f3f3f3">                 writeProgess(<span style="color:#a31515">&quot;F&quot;</span>);</li>
<li>             }</li>
<li style="background: #f3f3f3">         }</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">         writeProgess(<span style="color:#a31515">&quot;*&quot;</span>);</li>
<li>         System.Threading.<span style="color:#2b91af">Thread</span>.Sleep(60000); <span style="color:#008000">// Pause 1 minute</span></li>
<li style="background: #f3f3f3">     });</li>
<li> }</li>
</ol></div>
</p></div>
</p></div>
</p>
<p>My resume function works a follows: batch 100 records at a time (across 2 threads), process and wait for minute for the queue to clear. The Parallel function Partitioner is another favourite from the parallel library :</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:61ebed08-6966-4582-9b66-17f37d11be28" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#2b91af">Parallel</span>.ForEach(<span style="color:#2b91af">Partitioner</span>.Create(0, jobs.Count, blkSize), ops, t =&gt;</li>
<li style="background: #f3f3f3">{</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>and this will get the next block of records:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:06910406-8b9b-4eae-a9dc-48685834766e" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#008000">// get a block of records</span></li>
<li style="background: #f3f3f3"> <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Entity</span>&gt; _jobs = jobs.Skip(t.Item1).Take(blkSize).ToList();</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>Running this process also reduces strain on the CRM Server therefore allowing other jobs to be actioned.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=224</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Invalid User Authorisation</title>
		<link>http://blog.xrm-services.co.uk/?p=222</link>
		<comments>http://blog.xrm-services.co.uk/?p=222#comments</comments>
		<pubDate>Sat, 29 Dec 2012 11:40:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=222</guid>
		<description><![CDATA[“The user authentication passed to the platform is not valid” Over the Xmas break I decided to rebuild my lab servers from the ISO upwards. Limited on HW and memory, I planned on the the following config: Box 1 : &#8230; <a href="http://blog.xrm-services.co.uk/?p=222">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>“The user authentication passed to the platform is not valid”</p>
<p>Over the Xmas break I decided to rebuild my lab servers from the ISO upwards. Limited on HW and memory, I planned on the the following config:</p>
<p>Box 1 : AD, SQL, CRM</p>
<p>Box 2: Windows 7 client</p>
<p>Simple?</p>
<p>In my haste, I installed CRM 2011 on the DC using the “Network Service” account. All appeared to be fine until I tried to access the discovery service. OK, a quick repair to a “proper” account failed also.</p>
<p>My only solution was to uninstall CRM and reinstall with a “Domainuser” account.</p>
<p>Lesson learnt : Don’t install CRM 2011 on a DC using “Network Service” as the CRM accounts.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=222</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A parallel approach to CRM 2011</title>
		<link>http://blog.xrm-services.co.uk/?p=221</link>
		<comments>http://blog.xrm-services.co.uk/?p=221#comments</comments>
		<pubDate>Fri, 28 Dec 2012 11:45:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=221</guid>
		<description><![CDATA[I’m reading a lot of blog posts where people are starting to use the parallel libraries in CRM development. I’ve been using the C# .NET 4.0 parallel library for a while. Firstly, the Parallel.Invoke method, This allows the running of &#8230; <a href="http://blog.xrm-services.co.uk/?p=221">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I’m reading a lot of blog posts where people are starting to use the parallel libraries in CRM development. I’ve been using the C# .NET 4.0 parallel library for a while.</p>
<p>Firstly, the <strong>Parallel.Invoke</strong> method, This allows the running of processes in parallel. A simple example of this is:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:686d0e2e-32b6-4dd8-93b3-e902846626ca" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#2b91af">Parallel</span>.Invoke</li>
<li style="background: #f3f3f3">    (</li>
<li>        () =&gt;</li>
<li style="background: #f3f3f3">        {</li>
<li>            currencies = pCrmHelper.CrmHelper.CuroFunctions.GetAllCurrencies();</li>
<li style="background: #f3f3f3">            <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Currencies fetched&quot;</span>);</li>
<li>        },</li>
<li style="background: #f3f3f3">        () =&gt;</li>
<li>        {</li>
<li style="background: #f3f3f3">            provider = getProviderFromTenant(CuroTenant.OrgName);</li>
<li>            <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Providers fetched&quot;</span>);</li>
<li style="background: #f3f3f3">        },</li>
<li>        () =&gt;</li>
<li style="background: #f3f3f3">        {</li>
<li>            curoHoldings = curoFundActions.GetCuroHoldings();</li>
<li style="background: #f3f3f3">            <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&quot;Holdings fetched&quot;</span>);</li>
<li>        }</li>
<li style="background: #f3f3f3">    );</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>The above snippet just demonstrates that I want to fetch currencies, providers and holdings at the same time.&nbsp; The Invoke is completed when the longest running routine is complete. Time saving = “sum of the time to complete the slowest functions”</p>
<p>Secondly, the <strong>Parallel.ForEach</strong> method, this simply allows the iteration through a collection of objects and runs each on a separate thread.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dc22711c-7d74-4d19-a588-f9e5e78bb4e3" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#2b91af">ParallelOptions</span> ops = <span style="color:#0000ff">new</span> <span style="color:#2b91af">ParallelOptions</span>();</li>
<li style="background: #f3f3f3">ops.MaxDegreeOfParallelism = 6;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#2b91af">Parallel</span>.ForEach(incomeProfiles,ops,incomeProfile =&gt;</li>
<li>{</li>
<li style="background: #f3f3f3">    utility.ProcessIncomeprofile(incomeProfile, incomeProfile.Id, <span style="color:#a31515">&quot;jit&quot;</span>);</li>
<li>});</li>
</ol></div>
</p></div>
</p></div>
</p>
<p>&nbsp;</p>
<p>The above runs through a collection of incomeprofiles and actions each incomeprofile on a separate thread. The current thread can be identified by the </p>
<p>“Thread.CurrentThread.ManagedThreadId”</p>
<p>The Parallel library will manage the threadpool and ensure you will have a new thread, once the thread has been completed its returned to the pool.&nbsp; In the context of CRM this can be quite useful.</p>
<p>Within the above process I use a CRM library (that connects to CRM). I can either instantiate the library outside the loop – this is not a good idea as it becomes not very thread safe and a bottleneck – invalidating the use of parallelism. My preferred approach is to store instantiated services and index them by the current managed threadid, by doing this I can reuse CRM library services:</p>
<p>This code snippet controls this process:</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:be016eab-1d07-47e6-868e-7bb8b915433e" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> Collection of started Services for the threads</span></li>
<li><span style="color:#808080">///</span><span style="color:#008000"> Key ID = OrgName_ThreadId</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li><span style="color:#0000ff">private</span> Dictionary&lt;<span style="color:#0000ff">string</span>, CrmHelper&gt; _services = <span style="color:#0000ff">new</span> Dictionary&lt;<span style="color:#0000ff">string</span>, CrmHelper&gt;();</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> Get/Start a crm service from a pooled collection</span></li>
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;ThreadId&quot;&gt;</span><span style="color:#008000">Entry to the dictionary format: [OrgName_ThreadId] </span><span style="color:#808080">&lt;/param&gt;</span></li>
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;CuroTenant&quot;&gt;&lt;/param&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;returns&gt;&lt;/returns&gt;</span></li>
<li><span style="color:#0000ff">public</span> CrmHelper GetCrmService(<span style="color:#0000ff">int</span> ThreadId, <span style="color:#0000ff">string</span> OrgName)</li>
<li style="background: #f3f3f3">{</li>
<li>    CrmHelper currentService;</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>    <span style="color:#008000">// Was a service already created for this thread ID?</span></li>
<li style="background: #f3f3f3">    <span style="color:#0000ff">if</span> (_services.TryGetValue(OrgName + <span style="color:#a31515">&quot;_&quot;</span> + ThreadId, <span style="color:#0000ff">out</span> currentService))</li>
<li>    {</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">return</span> currentService;</li>
<li>    }</li>
<li style="background: #f3f3f3">    <span style="color:#0000ff">else</span></li>
<li>    {</li>
<li style="background: #f3f3f3">        <span style="color:#008000">// Configure the CRM service </span></li>
<li>        currentService = <span style="color:#0000ff">new</span> CrmHelper(OrgName);</li>
<li style="background: #f3f3f3">        currentService.ConnectCrm();</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">        <span style="color:#008000">// Dictionary Objects aren&#39;t thread safe </span></li>
<li>        <span style="color:#0000ff">lock</span> (((ICollection)_services).SyncRoot)</li>
<li style="background: #f3f3f3">        {</li>
<li>            <span style="color:#008000">// Cache the instance for this thread ID </span></li>
<li style="background: #f3f3f3">            Debug.WriteLine(<span style="color:#a31515">&quot;New connection &quot;</span> + OrgName + <span style="color:#a31515">&quot;_&quot;</span> + ThreadId.ToString() + <span style="color:#a31515">&quot; created&quot;</span>);</li>
<li>            _services.Add(OrgName + <span style="color:#a31515">&quot;_&quot;</span> + ThreadId.ToString(), currentService);</li>
<li style="background: #f3f3f3">        }</li>
<li>        <span style="color:#0000ff">return</span> currentService;</li>
<li style="background: #f3f3f3">    }</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
</p>
<p>The routine locks the dictionary object therefore preventing cross thread issues. A property on the main class allows for a new instance or existing instance of the service class to be returned:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:07b7dd5f-447a-41bc-ab16-f573dcc023ba" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> Returns a new instant of the CRM serivce</span></li>
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">public</span> <span style="color:#2b91af">CrmHelper</span> CrmHelper</li>
<li>{</li>
<li style="background: #f3f3f3">    <span style="color:#0000ff">get</span></li>
<li>    {</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">if</span> (tenant != <span style="color:#0000ff">null</span>)</li>
<li>        {</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">return</span> GetCrmService(<span style="color:#2b91af">Thread</span>.CurrentThread.ManagedThreadId, tenant);</li>
<li>        }</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">else</span></li>
<li>        {</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">Exception</span>(<span style="color:#a31515">&quot;GetCrmService failed due to &#39;TenantScope&#39; not supplied to constructor.&quot;</span>);</li>
<li>        }</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>        <span style="color:#0000ff">return</span> <span style="color:#0000ff">null</span>;</li>
<li style="background: #f3f3f3">    }</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>Note: the use of the ManagedThreadId to determine the index into the dictionary object.</p>
<p>The use of the parallel library improves performance considerably, however, it still can be tuned that little bit further!.</p>
<p>Increasing the throughput via the DefaultConnectionLimit (<a href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx">MSDN</a>), increasing this to 20 will give that little boost. I would, however, monitor the servers performance as this may have an adverse impact on the server!.</p>
<p>Hopefully, the above code snippets will inspire you to investigate further and lead you to writing faster and more efficient code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=221</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRM 2011 Auditing obscures the real error!!!</title>
		<link>http://blog.xrm-services.co.uk/?p=219</link>
		<comments>http://blog.xrm-services.co.uk/?p=219#comments</comments>
		<pubDate>Sun, 25 Nov 2012 09:32:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CRM 2011]]></category>
		<category><![CDATA[crm 2011]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=219</guid>
		<description><![CDATA[I’ve just written a new plugin and made a typo in one of the selected attributes. The purpose of the plugin was simple (for this example), create an invoice from another entity and assign a tax code. The latter is &#8230; <a href="http://blog.xrm-services.co.uk/?p=219">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I’ve just written a new plugin and made a typo in one of the selected attributes. The purpose of the plugin was simple (for this example), create an invoice from another entity and assign a tax code. The latter is a lookup to a custom table called t4a_taxrating.</p>
<p>Whilst saving the parent entity that will trigger the plugin to create an invoice I get this:</p>
<p><a href="http://blog.xrm-services.co.uk/wp-content/uploads/2012/11/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.xrm-services.co.uk/wp-content/uploads/2012/11/image_thumb.png" width="244" height="137"></a></p>
<p>The download logfile shows little more info except which plugin failed.</p>
<p>Running through an attached debugger I still get the timeout on the creating of the invoice.</p>
<p>Checking the event logs on the server revealed this:</p>
<p><em>“Query execution time of 30.0 seconds exceeded the threshold of 10 seconds. Thread: 13; Database: OFFICE1V2_MSCRM; Query: select top 1 ObjectTypeCode from AuditBase where ([Action] = 100 and [ChangeData] = &#8221;t4a_taxrate&#8221;).”</em></p>
<p>A little more information, indicating the query is failing when reading the auditbase.</p>
<p>So, to remove auditing from the equation I switched it off completely (as this is a dev system it doesn’t matted about loosing data).</p>
<p>Back to the parent entity and saving the record no displays this:</p>
<p><a href="http://blog.xrm-services.co.uk/wp-content/uploads/2012/11/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.xrm-services.co.uk/wp-content/uploads/2012/11/image_thumb1.png" width="244" height="139"></a></p>
<p>The message now tells me there is a problem with a query, the plugin and the offending attribute.</p>
<p><strong>Summary</strong>:</p>
<ul>
<li>SQL Timeout</li>
<li>Check the event log – any hint of auditing exceeding threshholds</li>
<li>Switch off auditing to get the ‘real’ message.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=219</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRM 2011 / Sharepoint &#8211; Importing a solution failed</title>
		<link>http://blog.xrm-services.co.uk/?p=214</link>
		<comments>http://blog.xrm-services.co.uk/?p=214#comments</comments>
		<pubDate>Thu, 02 Aug 2012 08:19:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CRM 2011]]></category>
		<category><![CDATA[Sharepoint 2011]]></category>
		<category><![CDATA[crm 2011]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=214</guid>
		<description><![CDATA[Just another interesting observation about the Sharepoint integration to CRM 2011.&#160; I have customised the Document Location entities to include some additional fields.&#160; My dev environment worked fine. A solution was build and then moved to a vanilla and the &#8230; <a href="http://blog.xrm-services.co.uk/?p=214">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just another interesting observation about the Sharepoint integration to CRM 2011.&nbsp; I have customised the Document Location entities to include some additional fields.&nbsp; My dev environment worked fine. A solution was build and then moved to a vanilla and the import failed with the following:</p>
<p><a href="http://blog.xrm-services.co.uk/wp-content/uploads/2012/08/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.xrm-services.co.uk/wp-content/uploads/2012/08/image_thumb.png" width="505" height="363"></a></p>
<p>As this is a Vanilla system,&nbsp; Sharepoint has never been configured. The process of running the Document Management settings ALSO creates N:1 relationships between the Document Locations entity the entity to be enabled for sharepoint.</p>
<p>So, if you are importing a solution that contains the Document Locations entity – ensure the destination system is also setup with the same enabled entities </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=214</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010 slow to load&#8230;</title>
		<link>http://blog.xrm-services.co.uk/?p=210</link>
		<comments>http://blog.xrm-services.co.uk/?p=210#comments</comments>
		<pubDate>Tue, 24 Jul 2012 06:07:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[VS2010]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=210</guid>
		<description><![CDATA[For a while since loading Silverlight 4/5/SDK/Toolkit – I’ve been having issues with VS 2010 starting. It will take about +30 secs , the status bar indicates: Loading toolbox content from package Microsoft.VisualStudio.ide.toolboxcontrolinstaller… {guid} After this quick fix – all &#8230; <a href="http://blog.xrm-services.co.uk/?p=210">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a while since loading Silverlight 4/5/SDK/Toolkit – I’ve been having issues with VS 2010 starting. It will take about +30 secs , the status bar indicates:</p>
<p>Loading toolbox content from package Microsoft.VisualStudio.ide.toolboxcontrolinstaller… {guid}</p>
<p>After this quick fix – all projects load instantly (i.e &lt; 5 secs from tfs)</p>
<p>NOTE: Ensure you have a backup of the registry before performing this:</p>
<p>1. Close all instances of VS 2010</p>
<p>2. Using RegEdit, rename all instances of the key {2c298b35-07da-45f1-96a3-be55d91c8d7a} on the machine you are having performance problems with</p>
<p>3. Relaunch VS 2010, In the toolbox, Right Click + Resettoolbox.</p>
<p>The last operation will reinstate your custom toolbox.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=210</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PixRM 2011</title>
		<link>http://blog.xrm-services.co.uk/?p=209</link>
		<comments>http://blog.xrm-services.co.uk/?p=209#comments</comments>
		<pubDate>Sun, 10 Jun 2012 16:37:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CRM 2011]]></category>
		<category><![CDATA[imagehandling]]></category>
		<category><![CDATA[pixrm]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=209</guid>
		<description><![CDATA[2012-06-10 16:37:19 <a href="http://blog.xrm-services.co.uk/?p=209">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometime ago, I wrote a complete image handling application for CRM 4.0 called PixRM. Over the past week I decided it was time to update the product to support Microsoft Dynamics CRM 2011.</p>
<p>Gallery view</p>
<p><a href="http://blog.xrm-services.co.uk/wp-content/uploads/2012/06/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.xrm-services.co.uk/wp-content/uploads/2012/06/image_thumb.png" width="444" height="299"></a></p>
<p>Detail View: (click on the image above)</p>
<p><a href="http://blog.xrm-services.co.uk/wp-content/uploads/2012/06/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.xrm-services.co.uk/wp-content/uploads/2012/06/image_thumb1.png" width="308" height="313"></a></p>
<p><strong>Summary of features:</strong></p>
<ul>
<li>Gallery view of image attachments (jpg, bmp, gif)</li>
<li>Image Detail record created for each image.</li>
<li>Additional details extracted from jpg files include, GPS coordinates, image date/time, Camera make &amp; model.</li>
<li>Easy to configure.</li>
<li>Support for on-premise, Microsoft Online and partner hosted.</li>
</ul>
<p>Ideal for recording and previewing images stored against record. Ideal for housing , estate agents (real estate), commercial property.</p>
<p>Drop me an email if you would like more info <a href="mailto:mread@mike-read.co.uk">mread@mike-read.co.uk</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=209</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create, Send, Route an Email with a template an attachment</title>
		<link>http://blog.xrm-services.co.uk/?p=204</link>
		<comments>http://blog.xrm-services.co.uk/?p=204#comments</comments>
		<pubDate>Sun, 20 May 2012 09:44:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CRM 2011]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=204</guid>
		<description><![CDATA[As the title suggests, I want to Create an email from a template and attach a file.&#160; I also want the option to send the email or route to a queue for validation before manually hitting Send. The purpose for &#8230; <a href="http://blog.xrm-services.co.uk/?p=204">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As the title suggests, I want to Create an email from a template and attach a file.&nbsp; I also want the option to send the email or route to a queue for validation before manually hitting Send.</p>
<p>The purpose for the is an invoice process. Generate a batch of invoices, create a PDF from a PDF template , attach the file to a templated email etc…</p>
<p>Firstly, create an email from a template.&nbsp; The template has been created and is saved as an Email Template:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:746056e5-d761-45a8-a1ab-352fa291da97" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#008000">// Create an e-mail message using a template.</span></li>
<li style="background: #f3f3f3"><span style="color:#2b91af">InstantiateTemplateRequest</span> instTemplateReq = <span style="color:#0000ff">new</span> <span style="color:#2b91af">InstantiateTemplateRequest</span></li>
<li>{</li>
<li style="background: #f3f3f3">    TemplateId = fetchTemplateId(LocalName),</li>
<li>    ObjectId = Id,</li>
<li style="background: #f3f3f3">    ObjectType = <span style="color:#a31515">&quot;invoice&quot;</span></li>
<li>};</li>
<li style="background: #f3f3f3"><span style="color:#2b91af">InstantiateTemplateResponse</span> instTemplateResp = <span style="color:#0000ff">null</span>;</li>
<li><span style="color:#2b91af">Entity</span> eMail = <span style="color:#0000ff">null</span>; </li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">try</span></li>
<li style="background: #f3f3f3">{</li>
<li>    instTemplateResp = (<span style="color:#2b91af">InstantiateTemplateResponse</span>)helper.Execute(instTemplateReq, <span style="color:#0000ff">true</span>);</li>
<li style="background: #f3f3f3">}</li>
<li><span style="color:#0000ff">catch</span> (<span style="color:#2b91af">Exception</span> ex)</li>
<li style="background: #f3f3f3">{</li>
<li>    log.Write(<span style="color:#0000ff">this</span>, <span style="color:#a31515">&quot;Failed to create email from template (using &quot;</span> + LocalName + <span style="color:#a31515">&quot;) &quot;</span> + ex.Message.ToString());</li>
<li style="background: #f3f3f3">}</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>Using the InstantiateTemplateRequest, I need to specify the templateid (derived the the PDF template name),the objectid (the previously created invoiceid) and the objecttype – the invoice.</p>
<p>The result is an email Entity:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:622c6051-70a0-4b74-9046-a0ac3014bd35" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'',Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li>eMail = instTemplateResp.EntityCollection.Entities[0];</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>From this point I can create my PDF and attach:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ebf3880-894a-439d-9640-38d90f11a00e" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#008000">// Fetch invoicenumber and add to parameters</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">string</span> prefix = <span style="color:#a31515">&quot;topmostSubform[0].Page1[0].&quot;</span>;</li>
<li><span style="color:#0000ff">string</span> invno = fetchInvoiceNumber(Id);</li>
<li style="background: #f3f3f3">Parameters.Add(<span style="color:#0000ff">new</span> <span style="color:#2b91af">PDFParameter</span>() { PathName = prefix + <span style="color:#a31515">&quot;invno[0]&quot;</span>, Value = invno });</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">writeEmailAttachmentToCrm(emailId, <span style="color:#a31515">&quot;email&quot;</span>, invno + <span style="color:#a31515">&quot;.pdf&quot;</span>, createPDFArray(LocalName, Parameters));</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>Depending on the parameters passed I need to either SEND or ROUTE to an invoice queue for checking:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:59930b92-7833-4ce8-b2eb-3a5320a1cd72" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">if</span> (Send)</li>
<li>{</li>
<li style="background: #f3f3f3">    <span style="color:#008000">// Send the email</span></li>
<li>    <span style="color:#2b91af">SendEmailRequest</span> send = <span style="color:#0000ff">new</span> <span style="color:#2b91af">SendEmailRequest</span>();</li>
<li style="background: #f3f3f3">    send.EmailId = emailId;</li>
<li>    send.TrackingToken = <span style="color:#a31515">&quot;&quot;</span>;</li>
<li style="background: #f3f3f3">    send.IssueSend = <span style="color:#0000ff">true</span>;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#008000">//SendEmailResponse sendEmailresp = (SendEmailResponse)helper.Execute(send, true);</span></li>
<li>}</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">else</span></li>
<li>{</li>
<li style="background: #f3f3f3">    <span style="color:#008000">// write to queue</span></li>
<li>    <span style="color:#2b91af">AddToQueueRequest</span> routeRequest = <span style="color:#0000ff">new</span> <span style="color:#2b91af">AddToQueueRequest</span></li>
<li style="background: #f3f3f3">    {</li>
<li>        Target = <span style="color:#0000ff">new</span> <span style="color:#2b91af">EntityReference</span>(<span style="color:#a31515">&quot;email&quot;</span>, emailId),</li>
<li style="background: #f3f3f3">        DestinationQueueId = <span style="color:#2b91af">Guid</span>.Parse(<span style="color:#a31515">&quot;3CEB6F78-2698-E111-9B55-782BCB776B8C&quot;</span>)</li>
<li>    };</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>    helper.Execute(routeRequest, <span style="color:#0000ff">true</span>);</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>During testing , I’ve taken precautions to NOT send emails:</p>
<p>1. Comment out the SendRequest</p>
<p>2. Hardcode the partyIds</p>
<p>3. Hardcode the Queue</p>
<p>Hopefully this demonstrates how easy it is to send templated emails with attachments.&nbsp; </p>
<p>Oh Yes – the PDF routines – using iTextSharp:</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7852719a-a09b-4578-b50f-a6d88fd8c55d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> Create a PDFstream from a localfile</span></li>
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;LocalName&quot;&gt;&lt;/param&gt;</span></li>
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;returns&gt;&lt;/returns&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">public</span> <span style="color:#2b91af">PDFData</span> CreatePDF(<span style="color:#2b91af">Guid</span> Id, <span style="color:#0000ff">string</span> LocalName, <span style="color:#2b91af">ObservableCollection</span>&lt;<span style="color:#2b91af">PDFParameter</span>&gt; Parameters)</li>
<li>{</li>
<li style="background: #f3f3f3">    <span style="color:#2b91af">PDFData</span> returnData = <span style="color:#0000ff">new</span> <span style="color:#2b91af">PDFData</span>();</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#0000ff">string</span> currentDir = <span style="color:#2b91af">AppDomain</span>.CurrentDomain.BaseDirectory + <span style="color:#a31515">@&quot;Templates&#92;&quot;</span>;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#2b91af">PdfReader</span> reader = <span style="color:#0000ff">new</span> <span style="color:#2b91af">PdfReader</span>(currentDir + LocalName );</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#008000">// filling in the form</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#2b91af">MemoryStream</span> op = <span style="color:#0000ff">new</span> <span style="color:#2b91af">MemoryStream</span>();</li>
<li>    <span style="color:#2b91af">PdfStamper</span> stamp1 = <span style="color:#0000ff">new</span> <span style="color:#2b91af">PdfStamper</span>(reader, op);</li>
<li style="background: #f3f3f3">    <span style="color:#2b91af">AcroFields</span> form1 = stamp1.AcroFields;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">PDFParameter</span> parameter <span style="color:#0000ff">in</span> Parameters)</li>
<li>    {</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">try</span></li>
<li>        {</li>
<li style="background: #f3f3f3">            form1.SetField(parameter.PathName, parameter.Value);</li>
<li>        }</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">catch</span> (<span style="color:#2b91af">Exception</span> ex)</li>
<li>        { }</li>
<li style="background: #f3f3f3">    }</li>
<li>    stamp1.FormFlattening = <span style="color:#0000ff">true</span>;</li>
<li style="background: #f3f3f3">    stamp1.Close();</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    returnData.Data = op.ToArray();</li>
<li>    returnData.Id = Id;</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>    op.Close();</li>
<li style="background: #f3f3f3">    op.Dispose();</li>
<li>    reader.Close();</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>    <span style="color:#0000ff">return</span> returnData;</li>
<li style="background: #f3f3f3">}</li>
</ol></div>
</p></div>
</p></div>
</p>
<p>The PDF files are preformatted with placeholders (fields) to be substituted here .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=204</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parse savedquery and userquery attributes with Linq</title>
		<link>http://blog.xrm-services.co.uk/?p=198</link>
		<comments>http://blog.xrm-services.co.uk/?p=198#comments</comments>
		<pubDate>Sun, 13 May 2012 08:51:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CRM 2011]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[savedquery]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[userquery]]></category>

		<guid isPermaLink="false">http://blog.xrm-services.co.uk/?p=198</guid>
		<description><![CDATA[I’ve been writing a Silverlight grid that displays columns from a CRM view.&#160; (dynamic grid,&#160; display labels as column names and built at runtime).&#160; Some challenges, the first being how to parse the output from the returned fetch query to &#8230; <a href="http://blog.xrm-services.co.uk/?p=198">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I’ve been writing a Silverlight grid that displays columns from a CRM view.&nbsp; (dynamic grid,&nbsp; display labels as column names and built at runtime).&nbsp; </p>
<p>Some challenges, the first being how to parse the output from the returned fetch query to get the view columns, linked entities and conditions.</p>
<p>Firstly, my fetchxml looks like this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:90e06f9f-4e0c-484f-b997-a8621fda86af" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li>            <span style="color:#0000ff">string</span> fetchXml = <span style="color:#a31515">@&quot;&lt;fetch mapping=&#39;logical&#39;&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#a31515">                                    &lt;entity name=&#39;{1}&#39;&gt;</span></li>
<li>    <span style="color:#a31515">                                    &lt;attribute name=&#39;name&#39;/&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#a31515">                                    &lt;attribute name=&#39;layoutxml&#39;/&gt;</span></li>
<li>    <span style="color:#a31515">                                    &lt;attribute name=&#39;fetchxml&#39;/&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#a31515">                                    &lt;filter type=&#39;and&#39;&gt;</span></li>
<li>        <span style="color:#a31515">                                    &lt;condition attribute=&#39;returnedtypecode&#39; operator=&#39;eq&#39; value=&#39;{0}&#39;/&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#a31515">                                    &lt;/filter&gt;</span></li>
<li><span style="color:#a31515">                                    &lt;/entity&gt;</span></li>
<li style="background: #f3f3f3">                                <span style="color:#a31515">&lt;/fetch&gt;</span></li>
<li>                            <span style="color:#a31515">&quot;</span>;</li>
</ol></div>
</p></div>
</p></div>
<p>{0} = either savedquery or userquery – depending on the purpose of the grid.</p>
<p>The output from the above used for the test code below:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fdfbab45-b3b7-40d7-a9d1-ce75173dbfae" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#0000ff">static</span> <span style="color:#0000ff">string</span> LayoutXml = <span style="color:#a31515">&quot;&lt;grid name=&#92;&quot;resultset&#92;&quot; object=&#92;&quot;1090&#92;&quot; jump=&#92;&quot;name&#92;&quot; select=&#92;&quot;1&#92;&quot; icon=&#92;&quot;1&#92;&quot; preview=&#92;&quot;1&#92;&quot;&gt;&lt;row name=&#92;&quot;result&#92;&quot; id=&#92;&quot;invoiceid&#92;&quot;&gt;&lt;cell name=&#92;&quot;customerid&#92;&quot; width=&#92;&quot;150&#92;&quot;/&gt;&lt;cell name=&#92;&quot;name&#92;&quot; width=&#92;&quot;300&#92;&quot;/&gt;&lt;cell name=&#92;&quot;invoicenumber&#92;&quot; width=&#92;&quot;125&#92;&quot;/&gt;&lt;cell name=&#92;&quot;t4a_collectionmethod&#92;&quot; width=&#92;&quot;125&#92;&quot;/&gt;&lt;cell name=&#92;&quot;t4a_invoicedate&#92;&quot; width=&#92;&quot;100&#92;&quot;/&gt;&lt;cell name=&#92;&quot;t4a_issueddate&#92;&quot; width=&#92;&quot;100&#92;&quot;/&gt;&lt;cell name=&#92;&quot;statecode&#92;&quot; width=&#92;&quot;100&#92;&quot;/&gt;&lt;cell name=&#92;&quot;totalamount&#92;&quot; width=&#92;&quot;100&#92;&quot;/&gt;&lt;cell name=&#92;&quot;t4a_adviserid&#92;&quot; width=&#92;&quot;150&#92;&quot;/&gt;&lt;cell name=&#92;&quot;a_550a704187f6e01187a9b8ac6f1693a8.fullname&#92;&quot; width=&#92;&quot;100&#92;&quot; disableSorting=&#92;&quot;1&#92;&quot;/&gt;&lt;/row&gt;&lt;/grid&gt;&quot;</span>;</li>
<li style="background: #f3f3f3"> <span style="color:#0000ff">static</span> <span style="color:#0000ff">string</span> FetchXml = <span style="color:#a31515">&quot;&lt;fetch version=&#92;&quot;1.0&#92;&quot; output-format=&#92;&quot;xml-platform&#92;&quot; mapping=&#92;&quot;logical&#92;&quot; distinct=&#92;&quot;false&#92;&quot;&gt;&lt;entity name=&#92;&quot;invoice&#92;&quot;&gt;&lt;attribute name=&#92;&quot;name&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;customerid&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;totalamount&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;statecode&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;t4a_issueddate&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;t4a_invoicedate&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;t4a_collectionmethod&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;t4a_adviserid&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;invoicenumber&#92;&quot;/&gt;&lt;attribute name=&#92;&quot;invoiceid&#92;&quot;/&gt;&lt;order attribute=&#92;&quot;customerid&#92;&quot; descending=&#92;&quot;false&#92;&quot;/&gt;&lt;link-entity name=&#92;&quot;systemuser&#92;&quot; from=&#92;&quot;systemuserid&#92;&quot; to=&#92;&quot;t4a_adviserid&#92;&quot; visible=&#92;&quot;false&#92;&quot; link-type=&#92;&quot;outer&#92;&quot; alias=&#92;&quot;a_550a704187f6e01187a9b8ac6f1693a8&#92;&quot;&gt;&lt;attribute name=&#92;&quot;fullname&#92;&quot;/&gt;&lt;/link-entity&gt;&lt;/entity&gt;&lt;/fetch&gt;&quot;</span>;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"> <span style="color:#0000ff">static</span> <span style="color:#0000ff">string</span> FetchConditionXml = <span style="color:#a31515">&quot;&lt;fetch version=&#92;&quot;1.0&#92;&quot; output-format=&#92;&quot;xml-platform&#92;&quot; mapping=&#92;&quot;logical&#92;&quot; distinct=&#92;&quot;false&#92;&quot;&gt;&lt;entity name=&#92;&quot;invoice&#92;&quot;&gt;&lt;attribute name=&#92;&quot;name&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;totalamount&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;customerid&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;statecode&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;t4a_issueddate&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;t4a_invoicedate&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;t4a_collectionmethod&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;t4a_adviserid&#92;&quot; /&gt;&lt;attribute name=&#92;&quot;invoicenumber&#92;&quot; /&gt;&lt;order attribute=&#92;&quot;t4a_invoicedate&#92;&quot; descending=&#92;&quot;true&#92;&quot; /&gt;&lt;filter type=&#92;&quot;and&#92;&quot;&gt;&lt;filter type=&#92;&quot;and&#92;&quot;&gt;&lt;condition attribute=&#92;&quot;statecode&#92;&quot; operator=&#92;&quot;eq&#92;&quot; value=&#92;&quot;0&#92;&quot; /&gt;&lt;condition attribute=&#92;&quot;duedate&#92;&quot; operator=&#92;&quot;last-x-years&#92;&quot; value=&#92;&quot;5&#92;&quot; /&gt;&lt;/filter&gt;&lt;/filter&gt;&lt;attribute name=&#92;&quot;invoiceid&#92;&quot; /&gt;&lt;/entity&gt;&lt;/fetch&gt;&quot;</span>;</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p><strong>1. Parse the display columns:</strong></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9be34f3b-16f2-45ae-a12e-01b43dfbd960" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#2b91af">XDocument</span> layoutRows = <span style="color:#2b91af">XDocument</span>.Parse(LayoutXml);</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">var</span> lrows = <span style="color:#0000ff">from</span> i <span style="color:#0000ff">in</span> layoutRows.Descendants(<span style="color:#a31515">&quot;grid&quot;</span>).Descendants(<span style="color:#a31515">&quot;row&quot;</span>).Descendants(<span style="color:#a31515">&quot;cell&quot;</span>)</li>
<li style="background: #f3f3f3">           <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span></li>
<li>           {</li>
<li style="background: #f3f3f3">               name = i.Attribute(<span style="color:#a31515">&quot;name&quot;</span>).Value</li>
<li>           };</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> item <span style="color:#0000ff">in</span> lrows)</li>
<li style="background: #f3f3f3">{</li>
<li>    <span style="color:#2b91af">Console</span>.WriteLine(item.name);</li>
<li style="background: #f3f3f3">}</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p><strong>2. Parse the “linked” entities for the view</strong></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fe657957-1cc9-4641-808c-5cae02c73c89" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#2b91af">XDocument</span> fetchRows = <span style="color:#2b91af">XDocument</span>.Parse(FetchXml);</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">var</span> frows = <span style="color:#0000ff">from</span> i <span style="color:#0000ff">in</span> fetchRows.Descendants(<span style="color:#a31515">&quot;fetch&quot;</span>).Descendants(<span style="color:#a31515">&quot;entity&quot;</span>).Descendants(<span style="color:#a31515">&quot;link-entity&quot;</span>)</li>
<li style="background: #f3f3f3">           <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span></li>
<li>           {</li>
<li style="background: #f3f3f3">               name = i.Attribute(<span style="color:#a31515">&quot;name&quot;</span>).Value,</li>
<li>               alias = i.Attribute(<span style="color:#a31515">&quot;alias&quot;</span>).Value </li>
<li style="background: #f3f3f3">           };</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> item <span style="color:#0000ff">in</span> frows)</li>
<li>{</li>
<li style="background: #f3f3f3">    <span style="color:#2b91af">Console</span>.WriteLine(item.name);</li>
<li>    <span style="color:#2b91af">Console</span>.WriteLine(item.alias);</li>
<li style="background: #f3f3f3">}</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p><strong>3. Parse the “condition&#8221; for the view</strong></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2d593056-a324-4e14-8df2-f9cfe18e0f34" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#2b91af">XDocument</span> fetchConditionRows = <span style="color:#2b91af">XDocument</span>.Parse(FetchConditionXml);</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">var</span> fcrows = <span style="color:#0000ff">from</span> i <span style="color:#0000ff">in</span> fetchConditionRows.Descendants(<span style="color:#a31515">&quot;fetch&quot;</span>).Descendants(<span style="color:#a31515">&quot;entity&quot;</span>).Descendants(<span style="color:#a31515">&quot;condition&quot;</span>)</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span></li>
<li>            {</li>
<li style="background: #f3f3f3">                attribute = i.Attribute(<span style="color:#a31515">&quot;attribute&quot;</span>).Value,</li>
<li>                cOperator = i.Attribute(<span style="color:#a31515">&quot;operator&quot;</span>).Value,</li>
<li style="background: #f3f3f3">                value = i.Attribute(<span style="color:#a31515">&quot;value&quot;</span>).Value</li>
<li>            };</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> item <span style="color:#0000ff">in</span> fcrows)</li>
<li style="background: #f3f3f3">{</li>
<li>    <span style="color:#2b91af">Console</span>.WriteLine(item.attribute);</li>
<li style="background: #f3f3f3">    <span style="color:#2b91af">Console</span>.WriteLine(item.cOperator);</li>
<li>    <span style="color:#2b91af">Console</span>.WriteLine(item.value);</li>
<li style="background: #f3f3f3">    <span style="color:#2b91af">Console</span>.WriteLine();</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>&nbsp;</p>
<p>The above three routines demonstrate how to extract the necessary attributes using Linq.</p>
<p>NOTE: If you are using Silverlight, you will need to add System.Xml.Linq as a reference to use XDocument.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xrm-services.co.uk/?feed=rss2&#038;p=198</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
