<?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>MSCRM Blogger &#187; Scoperta</title>
	<atom:link href="http://mscrmblogger.com/category/scoperta/feed/" rel="self" type="application/rss+xml" />
	<link>http://mscrmblogger.com</link>
	<description>Achieving it all with Microsoft Dynamics CRM™</description>
	<lastBuildDate>Wed, 30 Nov 2011 00:34:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CRM 2011: Star Rating Form Control</title>
		<link>http://mscrmblogger.com/2011/09/20/crm-2011-star-rating-control/</link>
		<comments>http://mscrmblogger.com/2011/09/20/crm-2011-star-rating-control/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 02:06:14 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[General API Usage]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Scoperta]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics crm]]></category>
		<category><![CDATA[Microsoft Dynamics CRM 2011]]></category>
		<category><![CDATA[rating]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Web Resource]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/2011/09/20/crm-2011-star-rating-control/</guid>
		<description><![CDATA[<p>Another HTML control example that adds a star rating form control to CRM 2011 as a web-resource.  It includes a managed solution that you can download and install as well as the source and all images used in creating the solution.</p>]]></description>
			<content:encoded><![CDATA[<p>To expand on the technique used for my previous post on <a href="http://mscrmblogger.com/2011/05/11/crm-2011-making-the-state-field-a-drop-down/">making the state field a drop down</a> here is a star rating field control so that you can get a nice visual star rating control that is configurable.</p>
<p>Below is an example of the star rating control in action, and you can <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/RatingControl_1_0_managed.zip'>click here to download a solution</a> to import the web-resources into your CRM deployment (it is a managed solution with no entities).</p>
<p><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/092111_0206_CRM2011Star11.png" alt="" class="aligncenter size-full" /></p>
<p>Ok, once you have the web-resource loaded into your CRM deployment, you&#8217;ll need to create a new field to store the rating and put it on the form, but uncheck the visible box.</p>
<p><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/092111_0206_CRM2011Star21.png" alt="" class="aligncenter size-full" /></p>
<p>Add the Web-Resource to the form, and check the box to <strong>display the label on the form</strong>.</p>
<p>Then enter your parameters (I like using a pipe as a separator).  The available parameters are:</p>
<ul>
<li><strong>min</strong>: minimum star rating – really should always be 1</li>
<li><strong>max</strong>: maximum star rating – maybe 5 or 10</li>
<li><strong>field</strong>: the CRM field to store the value in</li>
<li><strong>showvalue</strong>: whether or not to display the numerical value</li>
</ul>
<p><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/092111_0206_CRM2011Star31.png" alt="" class="aligncenter size-full" /></p>
<p>Make sure to click on the formatting tab and set the <strong>number of rows to 1</strong>, <strong>scrolling to Never</strong>, and check the box to <strong>display the border</strong>.</p>
<p><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/092111_0206_CRM2011Star41.png" alt="" class="aligncenter size-full" /></p>
<p>Then move the hidden field down and out the way.  If you have a lot of fields you are accessing through form scripts you could just drop them into a hidden section.</p>
<p><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/092111_0206_CRM2011Star51.png" alt="" class="aligncenter size-full" /></p>
<p>Now that you know how to set it up, let&#8217;s go ahead and look at the code.</p>
<pre name="code" class="html">
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
  &lt;title&gt;Rating Control&lt;/title&gt;
  &lt;link href=&quot;/_common/styles/fonts.css.aspx?lcid=1033&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
  &lt;link href=&quot;/_common/styles/global.css.aspx?lcid=1033&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
  &lt;link href=&quot;/_common/styles/select.css.aspx?lcid=1033&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
var Rating = {};

// Default Values
Rating.ShowValue = false;
Rating.Max = 5;
Rating.Min = 1;
Rating.Field = '';
Rating.Value = null;

Rating.Highlight = function(index)
{
  var val = document.getElementById('rating_value');
  if (index===null) {
    index = -1;
    val.innerHTML = '[Not Set]';
  } else {
    val.innerHTML = '['+index+'/'+Rating.Max+']';
  }
  for(var i=Rating.Min; i&lt;=Rating.Max;i++)
  {
    if (i&lt;=index) {
      document.getElementById(&quot;rating_&quot;+i).className = &quot;staron&quot;;
    } else {
      document.getElementById(&quot;rating_&quot;+i).className = &quot;staroff&quot;;
    }
  }
};

Rating.HolderRollover = function() {
  if (Rating.Value !== null) {
    var r = document.getElementById('rating_remove');
    r.className = 'stardel';
  }
};

Rating.HolderRollout = function() {
  var r = document.getElementById('rating_remove');
  r.className = 'stardel2';
};

Rating.Rollover = function(index) {
  Rating.Highlight(index);
};

Rating.Rollout = function()
  {
  Rating.Highlight(Rating.Value);
};

Rating.Set = function(index) {
  Rating.Value = index;
  if (index&lt;0) {
    parent.Xrm.Page.data.entity.attributes.get(Rating.Field).setValue(null);
  } else {
    parent.Xrm.Page.data.entity.attributes.get(Rating.Field).setValue(Rating.Value);
  }
  Rating.Highlight(index);
};

Rating.Initialize = function() {
  var data = WebResource.GetDataParams();
  for (var i in data)
  {
    switch (data[i][0].toLowerCase())
        {
          case 'min': Rating.Min = parseInt(data[i][1],10); break;
          case 'max': Rating.Max = parseInt(data[i][1],10); break;
          case 'field': Rating.Field = data[i][1]; break;
          case 'showvalue': Rating.ShowValue = (data[i][1] == 'true'); break;
          default:break;
        }
  }
  var d = document.getElementById('starholder');
  for (var j=Rating.Min;j&lt;=Rating.Max;j++)
  {
    var el = &quot;&lt;span id='rating_&quot;+j+&quot;' &quot; +
             &quot;onmouseover='Rating.Rollover(&quot;+j+&quot;);' &quot; +
             &quot;onmouseout='Rating.Rollout();' &quot; +
             &quot;onclick='Rating.Set(&quot;+j+&quot;);' /&gt;&quot;;
    d.innerHTML += el;
  }

  var rel = &quot;&lt;span id='rating_remove' class='stardel2' &quot; +
            &quot;onclick='Rating.Set(null);' onmouseover='Rating.Rollover(null);' /&gt;&quot;;
  d.innerHTML += rel;

  var val = &quot;&lt;span id='rating_value' class='value' &quot; +
            (Rating.ShowValue ? &quot;&quot; : &quot;style='display:none' &quot;) +
            &quot;/&gt;&quot;;
  d.innerHTML += val; 

  Rating.Value = parent.Xrm.Page.data.entity.attributes.get(Rating.Field).getValue();
  Rating.Highlight(Rating.Value);
};

var WebResource = {};

WebResource.GetDataParams = function()
{ //modified version of: http://technet.microsoft.com/en-us/library/gg327945.aspx
  //Get the any query string parameters and load them
  //into the vals array

  var vals = new Array();
  if (location.search !== &quot;&quot;)
  {
    vals = location.search.substr(1).split(&quot;&amp;&quot;);
    for (var i in vals)
    {
      vals[i] = vals[i].replace(/\+/g, &quot; &quot;).split(&quot;=&quot;);
    }

    //look for the parameter named 'data'
    var found = false;
        var datavals;
    for (var j in vals)
    {
      if (vals[j][0].toLowerCase() == &quot;data&quot;)
      {
        found = true;
        datavals = decodeURIComponent(vals[j][1]).split(&quot;|&quot;);
        for (var k in datavals)
        {
          datavals[k] = datavals[k].replace(/\+/g, &quot; &quot;).split(&quot;=&quot;);
        }
        break;
      }
    }
    if (found) { return datavals; }
  }
  return null;
};
  &lt;/script&gt;
  &lt;style type=&quot;text/css&quot;&gt;
.staroff,.staron,.stardel,.stardel2 {
	height:15px;
	margin:1px 1px 1px 2px;
	width:15px
}

staroff,.staron,.stardel {
	background:no-repeat
}

.starholder {
	background:#FFF;
	padding:1px
}

.stardel {
	background:url(remove.png)
}

.staron {
	background:url(staron.png)
}

.staron,.staroff {
	margin-right:5px
}

.staroff {
	background:url(staroff.png)
}

.value {
	font:11px segoe ui,tahoma,arial;
	color:#000;
	height:17px;
	vertical-align:middle
}
  &lt;/style&gt;
&lt;/head&gt;

&lt;body onload=&quot;Rating.Initialize();&quot;&gt;
  &lt;table cellspacing=&quot;0&quot;
         cellpadding=&quot;0&quot;
         width=&quot;100%&quot;
         summary=&quot;star table&quot;&gt;
    &lt;tr&gt;
      &lt;td id=&quot;cell_dd&quot;&gt;
        &lt;div id=&quot;starholder&quot;
             style=&quot;width:100%;&quot;
             onmouseover=&quot;Rating.HolderRollover();&quot;
             onmouseout=&quot;Rating.HolderRollout();&quot;&gt;&lt;/div&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<table>
<tr>
<td>These are the image files used:</td>
<td>
<a href="http://mscrmblogger.com/wp-content/uploads/2011/09/msblog_ratingstaron.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/msblog_ratingstaron.png" alt="" title="msblog_ratingstaron" width="15" height="15" class="aligncenter size-full wp-image-785" /></a></td>
<td>
<a href="http://mscrmblogger.com/wp-content/uploads/2011/09/msblog_ratingstaroff.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/msblog_ratingstaroff.png" alt="" title="msblog_ratingstaroff" width="15" height="15" class="aligncenter size-full wp-image-784" /></a></td>
<td>
<a href="http://mscrmblogger.com/wp-content/uploads/2011/09/msblog_ratingremove.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/msblog_ratingremove.png" alt="" title="msblog_ratingremove" width="15" height="15" class="aligncenter size-full wp-image-783" /></a></td>
<td>(<i>they are hidden in the managed solution</i>)</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/09/20/crm-2011-star-rating-control/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CRM Workflow Manipulation Library</title>
		<link>http://mscrmblogger.com/2010/07/08/crm-workflow-manipulation-library/</link>
		<comments>http://mscrmblogger.com/2010/07/08/crm-workflow-manipulation-library/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 22:55:43 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Scoperta]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 4]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[equations]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics CRM 4]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=231</guid>
		<description><![CDATA[<p>The <a href="http://manipulationlibrary.codeplex.com/">CRM Workflow Manipulation Library</a> is now on CodePlex.  The CRM Workflow Manipulation Library for CRM is a set of custom workflows for OnPremise Microsoft Dynamics® CRM to solve equations, manipulates strings, perform regex (regular expression) formatting and matching, as well as SoundEx and Metaphone-Like codification.</p>]]></description>
			<content:encoded><![CDATA[<p>Microsoft Dynamics CRM’s workflow designer is built right into the web-application and provides a way to conditionally perform actions in CRM.  With CRM on-premise, custom workflow assemblies can be uploaded to the server and accessed through the web-interface.  The <a href="http://manipulationlibrary.codeplex.com/">CRM Workflow Manipulation Library</a> provides additional workflow actions to perform calculations and manipulate strings.</p>
<p></p>
<p>Two of its most notable capabilities are its ability to perform mathematical equations and phonetic codification solving for duplicate matching.</p>
<p></p>
<p>Sometimes you may want to calculate a percentage based on some of the fields on an opportunity, or you may want to perform a calculation to make a decision on who should work on a particular task.  The solve equation workflow allows you to pass parameters and specify a formula for it to solve.</p>
<p></p>
<p><b>For example:</b></p>
<table>
<tr style="font-weight:bold">
<td>Workflow Field</td>
<td>Value</td>
</tr>
<tr>
<td>Formula:</td>
<td>min(@a,@b)*@c</td>
</tr>
<tr>
<td>@a:</td>
<td>100</td>
</tr>
<tr>
<td>@b:</td>
<td>125</td>
</tr>
<tr>
<td>@c:</td>
<td>4</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>Result</td>
<td>400</td>
</tr>
</table>
<p>
</p>
<p></p>
<p>The benefit is that the solver can help you calculate values to include in an email or store data back to CRM.  It does more than just basic math and can handle other constants and functions.  One of the constants it can handle is rand, which generates a number from 0 to 1 similar to excel, and it handles randbetween to generate a number between two values.</p>
<p></p>
<p>The Manipulation Library contains two phonetic codification systems, SoundEx and a Metaphone-like system.  Both of these can be used to convert text to a phonetic codified string that can then be compared for duplicate detection.  There are <a href="http://manipulationlibrary.codeplex.com/wikipage?title=Duplicate%20Checking%20with%20Metaphone&amp;referringTitle=Codify%20%28Metaphone%29">complete instructions on how to configure workflow to perform SoundEx or Metaphone duplicate detection</a> in the documentation.</p>
<p></p>
<p>The CRM Workflow Manipulation Library provides Calculation Utilities, RegEx Utilities, and String Utilities.  It is a feature-rich workflow extension that provides the ability to do much more with the data already in your CRM system, and is definitely worth checking out on <a href="http://manipulationlibrary.codeplex.com/">CodePlex</a>.  There are both Microsoft Dynamics CRM 4.0 and Microsoft Dynamics CRM 2011 versions on CodePlex.</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2010/07/08/crm-workflow-manipulation-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Workflow: Geocode (and correct) Addresses with Bing Maps</title>
		<link>http://mscrmblogger.com/2010/05/20/geocode_with_bing/</link>
		<comments>http://mscrmblogger.com/2010/05/20/geocode_with_bing/#comments</comments>
		<pubDate>Thu, 20 May 2010 17:59:03 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Scoperta]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[address]]></category>
		<category><![CDATA[bing]]></category>
		<category><![CDATA[bing maps]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 4]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[custom workflow]]></category>
		<category><![CDATA[geocode]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics CRM 4]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=221</guid>
		<description><![CDATA[Bing Maps are great.  You can geocode and correct your addresses.  While this isn't anything complicated, it is a good example of a custom workflow that uses an external webservice.]]></description>
			<content:encoded><![CDATA[<p>Bing Maps are great.  You can geocode and correct your addresses.  Depending on your level of queries and types of usage you may need to purchase credits to query Bing Maps, but I thought it was pretty straight forward. If you need to get a Bing Maps account, go <a href="http://www.microsoft.com/maps/developers/">here</a>.</p>
<p>The thing that makes this great is it is workflow.  It is not tied down to an entity.  You can use it on your custom entities, you can geocode your addresses, and correct them.  You can do address verification and geocoding.  You can control what you do using workflow.
</p>
<p>Ok, while this isn&#8217;t anything complicated, I thought it was a good example of a custom workflow that used an external webservice.  <i>Please don&#8217;t forget to create a signed key for your project.</i></p>
<p><b>Workflow Class:</b></p>
<pre name="code" class="csharp">
using System;
using System.ServiceModel;
using System.Text;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using BingWorkflow.BingMapsGeo;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Workflow;
using Microsoft.Win32;

namespace BingWorkflow
{
    [CrmWorkflowActivity("Bing Maps", "Geocode")]
    public class VerifyAddressUsingBingMapsActivity :
        SequenceActivity
    {
        // Activity code goes here. 

        public static DependencyProperty AddressCityProperty = DependencyProperty.Register(
            "AddressCity", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty AddressCountryProperty = DependencyProperty.Register(
            "AddressCountry", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty AddressLine1Property = DependencyProperty.Register(
            "AddressLine1", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty AddressPostalCodeProperty = DependencyProperty.Register(
            "AddressPostalCode", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty AddressStateProperty = DependencyProperty.Register(
            "AddressState", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty BingKeyProperty = DependencyProperty.Register(
            "BingKey", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputCityProperty = DependencyProperty.Register(
            "OutputCity", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputCountryProperty = DependencyProperty.Register(
            "OutputCountry", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputLatitudeProperty = DependencyProperty.Register(
            "OutputLatitude", typeof (CrmFloat), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputLine1Property = DependencyProperty.Register(
            "OutputLine1", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputLongitudeProperty = DependencyProperty.Register(
            "OutputLongitude", typeof (CrmFloat), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputMultipleFoundProperty = DependencyProperty.Register(
            "OutputMultipleFound", typeof (CrmBoolean), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputPostalCodeProperty = DependencyProperty.Register(
            "OutputPostalCode", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        public static DependencyProperty OutputStateProperty = DependencyProperty.Register(
            "OutputState", typeof (string), typeof (VerifyAddressUsingBingMapsActivity));

        [CrmInput("Address City")]
        public string AddressCity
        {
            get { return (string)GetValue(AddressCityProperty); }
            set { SetValue(AddressCityProperty, value); }
        }

        [CrmInput("Address Country")]
        public string AddressCountry
        {
            get { return (string)GetValue(AddressCountryProperty); }
            set { SetValue(AddressCountryProperty, value); }
        }

        [CrmInput("Address Line 1")]
        public string AddressLine1
        {
            get { return (string)GetValue(AddressLine1Property); }
            set { SetValue(AddressLine1Property, value); }
        }

        [CrmInput("Address Postal Code")]
        public string AddressPostalCode
        {
            get { return (string)GetValue(AddressPostalCodeProperty); }
            set { SetValue(AddressPostalCodeProperty, value); }
        }

        [CrmInput("Address State Or Province")]
        public string AddressState
        {
            get { return (string)GetValue(AddressStateProperty); }
            set { SetValue(AddressStateProperty, value); }
        }

        [CrmInput("Bing API Key")]
        public string BingKey
        {
            get { return (string)GetValue(BingKeyProperty); }
            set { SetValue(BingKeyProperty, value); }
        }

        [CrmOutput("City")]
        public string OutputCity
        {
            get { return (string)GetValue(OutputCityProperty); }
            set { SetValue(OutputCityProperty, value); }
        }

        [CrmOutput("Country Or Region")]
        public string OutputCountry
        {
            get { return (string)GetValue(OutputCountryProperty); }
            set { SetValue(OutputCountryProperty, value); }
        }

        [CrmOutput("Latitude")]
        public CrmFloat OutputLatitude
        {
            get { return (CrmFloat)GetValue(OutputLatitudeProperty); }
            set { SetValue(OutputLatitudeProperty, value); }
        }

        [CrmOutput("Line 1")]
        public string OutputLine1
        {
            get { return (string)GetValue(OutputLine1Property); }
            set { SetValue(OutputLine1Property, value); }
        }

        [CrmOutput("Longitude")]
        public CrmFloat OutputLongitude
        {
            get { return (CrmFloat)GetValue(OutputLongitudeProperty); }
            set { SetValue(OutputLongitudeProperty, value); }
        }

        [CrmOutput("Multiple Address Found")]
        public CrmBoolean OutputMultipleFound
        {
            get { return (CrmBoolean)GetValue(OutputMultipleFoundProperty); }
            set { SetValue(OutputMultipleFoundProperty, value); }
        }

        [CrmOutput("Postal Code")]
        public string OutputPostalCode
        {
            get { return (string)GetValue(OutputPostalCodeProperty); }
            set { SetValue(OutputPostalCodeProperty, value); }
        }

        [CrmOutput("State Or Province")]
        public string OutputState
        {
            get { return (string)GetValue(OutputStateProperty); }
            set { SetValue(OutputStateProperty, value); }
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            // Reset Outputs
            OutputLatitude = new CrmFloat();
            OutputLongitude = new CrmFloat();
            OutputLine1 = String.Empty;
            OutputCity = String.Empty;
            OutputState = String.Empty;
            OutputPostalCode = String.Empty;
            OutputMultipleFound = new CrmBoolean {Value = false};

            var key = BingKey;
            if (String.IsNullOrEmpty(key) || key.ToLower() == "registry")
            {
                key = GetAPIKeyFromRegistry();
            }

            // Create Bing Maps Request
            var bingRequest = new GeocodeRequest
                              {
                                  Credentials = new Credentials {ApplicationId = key},
                                  Query = AddressLine1 + ", " +
                                          AddressCity + ", " +
                                          AddressState + ", " +
                                          AddressPostalCode + ", " +
                                          AddressCountry
                              };

            // Filter for High Confidence
            var filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter {MinimumConfidence = Confidence.High};
            bingRequest.Options = new GeocodeOptions {Filters = filters};

            // Create Client
            GeocodeServiceClient bingClient = null;
            try
            {
                var geoBinding = new BasicHttpBinding(BasicHttpSecurityMode.None)
                                 {
                                     Name = "BasicHttpBinding_IGeocodeService",
                                     CloseTimeout = new TimeSpan(0, 1, 0),
                                     OpenTimeout = new TimeSpan(0, 1, 0),
                                     ReceiveTimeout = new TimeSpan(0, 10, 0),
                                     SendTimeout = new TimeSpan(0, 1, 0),
                                     AllowCookies = false,
                                     BypassProxyOnLocal = false,
                                     HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                                     MaxBufferSize = 65536,
                                     MaxBufferPoolSize = 524288,
                                     MaxReceivedMessageSize = 65536,
                                     MessageEncoding = WSMessageEncoding.Text,
                                     TextEncoding = Encoding.UTF8,
                                     TransferMode = TransferMode.Buffered,
                                     UseDefaultWebProxy = true
                                 };

                var geoEA =
                    new EndpointAddress("http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc");

                bingClient = new GeocodeServiceClient(geoBinding, geoEA);

                var bingResponse = bingClient.Geocode(bingRequest);

                if (bingResponse.Results != null &#038;&#038; bingResponse.Results.Length > 0)
                {
                    if (bingResponse.Results.Length > 1)
                    {
                        OutputMultipleFound.Value = true;
                    }

                    var bingResult = bingResponse.Results[0];

                    if (bingResult.Locations != null &#038;&#038; bingResult.Locations.Length > 0)
                    {
                        var bingLocation = bingResult.Locations[0];
                        OutputLatitude.Value = bingLocation.Latitude;
                        OutputLongitude.Value = bingLocation.Longitude;
                    }

                    var bingAddress = bingResult.Address;

                    OutputLine1 = bingAddress.AddressLine;
                    OutputPostalCode = bingAddress.PostalCode;
                    OutputCountry = bingAddress.CountryRegion;

                    OutputCity = String.IsNullOrEmpty(bingAddress.PostalTown)
                                     ? bingAddress.Locality
                                     : bingAddress.PostalTown;
                    OutputState = String.IsNullOrEmpty(bingAddress.AdminDistrict)
                                      ? bingAddress.District
                                      : bingAddress.AdminDistrict;
                }
            }
            catch (Exception ex)
            {
                throw new WorkflowTerminatedException(
                    "There was an error openning the connection to Bing Maps.", ex);
            }
            finally
            {
                // Close the client
                if (bingClient != null)
                {
                    bingClient.Close();
                }
            }

            return base.Execute(executionContext);
        }

        private static string GetAPIKeyFromRegistry()
        {
            // Opening the registry key
            var key = Registry.LocalMachine;
            if (key != null)
            {
                key = key.OpenSubKey("Software\\Microsoft Geocoder");
            }

            return key != null ? key.GetValue("APIKey").ToString() : null;
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2010/05/20/geocode_with_bing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Increasing Paging Limits</title>
		<link>http://mscrmblogger.com/2009/02/10/paging-limits/</link>
		<comments>http://mscrmblogger.com/2009/02/10/paging-limits/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 14:37:17 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Scoperta]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Unsupported]]></category>
		<category><![CDATA[advanced find]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=31</guid>
		<description><![CDATA[Paging Limits control how many items show up on the list pages in crm. Most notably advanced finds. I like to be able to display a lot of information, and I need to be able to run operations on more than 250 items. Using the following SQL query I was able to increase my paging <a href='http://mscrmblogger.com/2009/02/10/paging-limits/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Paging Limits control how many items show up on the list pages in crm.  Most notably advanced finds.  I like to be able to display a lot of information, and I need to be able to run operations on more than 250 items.  Using the following SQL query I was able to increase my paging limit to 1000.
</p>
<pre name="code" class="sql">
UPDATE UserSettings SET PagingLimit=1000 WHERE SystemUserId IN
(Select SystemUserId from SystemUserBase WHERE FullName like 'Carlton%')
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2009/02/10/paging-limits/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CRM 4 UserQuery Privileges for System Administrators</title>
		<link>http://mscrmblogger.com/2009/02/04/crm-4-userquery-privileges-for-system-administrators/</link>
		<comments>http://mscrmblogger.com/2009/02/04/crm-4-userquery-privileges-for-system-administrators/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 15:30:27 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[General API Usage]]></category>
		<category><![CDATA[Scoperta]]></category>
		<category><![CDATA[Unsupported]]></category>
		<category><![CDATA[advanced find]]></category>
		<category><![CDATA[assign]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[userquery]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=5</guid>
		<description><![CDATA[The CRM 4 System Administrators group does not have access to assign other people's saved advanced finds (user queries). I have created a single aspx page that uses the CRM SDK to allow a system administrator to assign any user's saved view to another user.]]></description>
			<content:encoded><![CDATA[<p>One of the problems I noticed in a recent upgrade to CRM 4 was that the System Administrators group did not have access to assign other people&#8217;s saved advanced finds (user queries). This is extremely annoying because I have a single aspx page that uses the CRM SDK to allow a system administrator to move any saved view from being owned by one person to another.
</p>
<p>Saved views are great for the organization, departments, and teams, but when a team uses them, often times they have someone create and share the views, then they leave the company or move to a different group within the company. They either can&#8217;t or no longer wish to be responsible for the advanced finds they have created and shared out with their fellow CRM users.</p>
<p>My custom page allows me to assign those views to someone else, allowing them to move the responisibility to another CRM user.</p>
<p>To update the CRM privileges to allow System Administrators full access (except for read) to all views, you can run the following sql code against the database.</p>
<p><strong>SQL Code:</strong></p>
<pre name="code" class="sql">UPDATE RolePrivileges SET PrivilegeDepthMask=128 WHERE RolePrivilegeId IN
(
  SELECT RolePrivilegeId FROM RolePrivileges r
  INNER JOIN PrivilegeBase pb ON r.privilegeid=pb.privilegeid
  INNER JOIN RoleBase rb ON r.roleid = rb.roleid
  WHERE pb.Name in
    ('prvAssignUserQuery',
     'prvShareUserQuery',
     'prvWriteUserQuery',
     'prvDeleteUserQuery',
     'prvCreateUserQuery'
    )
    AND rb.Name = 'System Administrator'
)</pre>
<p>The code for reassigning objects is really straight forward, it uses sql to get the lists, then uses the sdk to assign the items to other users.  It doesn&#8217;t fail because of the sql modification above.</p>
<p><b>ASP.Net Code</b></p>
<pre name="code" class="html">
&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="reassign.aspx.cs" Inherits="mst_Support.userquery.reassign" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;Untitled Page&lt;/title&gt;
    &lt;link href="../css/support.css" rel="stylesheet" type="text/css" /&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div align="center"&gt;
        &lt;asp:ScriptManager ID="smgr" runat="server"&gt;
        &lt;/asp:ScriptManager&gt;
        &lt;br /&gt;
        &lt;b&gt;Source User:&lt;/b&gt;
        &lt;asp:DropDownList ID="User_Src" runat="server" DataSourceID="crm_SystemUsers" DataTextField="FullName"
            DataValueField="SystemUserId" AutoPostBack="True" OnSelectedIndexChanged="User_Src_SelectedIndexChanged"&gt;
        &lt;/asp:DropDownList&gt;
        &lt;br /&gt;
        &lt;asp:UpdatePanel ID="upnQueries" runat="server" UpdateMode="Conditional"&gt;
            &lt;ContentTemplate&gt;
                &lt;br /&gt;
                &lt;b&gt;Saved Advanced Finds:&lt;br /&gt;
                &lt;/b&gt;
                &lt;asp:ListBox ID="QueueList" runat="server" SelectionMode="Multiple" Rows="15"&gt;&lt;/asp:ListBox&gt;
            &lt;/ContentTemplate&gt;
            &lt;Triggers&gt;
                &lt;asp:AsyncPostBackTrigger ControlID="User_Src" EventName="SelectedIndexChanged" /&gt;
            &lt;/Triggers&gt;
        &lt;/asp:UpdatePanel&gt;
        &lt;br /&gt;
        &lt;b&gt;Target User:&lt;/b&gt;
        &lt;asp:DropDownList ID="User_Target" runat="server"
            DataSourceID="crm_SystemUsers" DataTextField="FullName"
            DataValueField="SystemUserId"&gt;
        &lt;/asp:DropDownList&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;asp:Button ID="Assign" runat="server" onclick="Assign_Click" Text="Assign" /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;asp:Label ID="lblResponse" runat="server"&gt;&lt;/asp:Label&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;asp:SqlDataSource ID="crm_SystemUsers" runat="server" ConnectionString="&lt;%$ ConnectionStrings:crm_db %&gt;"
            SelectCommand="SELECT [SystemUserId], [FullName] FROM [SystemUserBase] WHERE ([IsDisabled] = @IsDisabled) ORDER BY [FullName]"
            ProviderName="&lt;%$ ConnectionStrings:crm_db.ProviderName %&gt;"&gt;
            &lt;SelectParameters&gt;
                &lt;asp:Parameter DefaultValue="false" Name="IsDisabled" Type="Boolean" /&gt;
            &lt;/SelectParameters&gt;
        &lt;/asp:SqlDataSource&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><b>C-Sharp code</b></p>
<pre name="code" class="csharp">using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using mst_Support.crmsdk;
using System.Web.Services.Protocols;
using System.Web.Configuration;

namespace mst_Support.userquery
{
    public partial class reassign : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void AssignUserQuery(string queryid, string userid)
        {
            try
            {
                    CrmAuthenticationToken token = new CrmAuthenticationToken();
                    token.AuthenticationType = 0; //AD
                    token.OrganizationName = "Your Organization"; //Could retrieve it.

                    CrmService crmService = new CrmService();
                    crmService.CrmAuthenticationTokenValue = token;
                    crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

                    //crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

                    SecurityPrincipal newowner = new SecurityPrincipal();
                    newowner.Type = SecurityPrincipalType.User;
                    newowner.PrincipalId = new Guid(userid);

                    TargetOwnedUserQuery query = new TargetOwnedUserQuery();
                    query.EntityId = new Guid(queryid);

                    // Create the request object.
                    AssignRequest assign = new AssignRequest();

                    // Set the properties of the request object.
                    assign.Assignee = newowner;
                    assign.Target = query;

                    AssignResponse assignResponse = (AssignResponse)crmService.Execute(assign);
            }
            catch (SoapException ex)
            {
                lblResponse.Text += "&lt;b&gt;Error: &lt;/b&gt;" +ex.ToString() +
                                    "&lt;br /&gt;&lt;br /&gt;\r\n";
                lblResponse.Text += "&lt;b&gt;Inner Detail: &lt;/b&gt;" + ex.Detail.InnerText +
                                    "&lt;br /&gt;&lt;br /&gt;\r\n";
                lblResponse.Text += "&lt;b&gt;InnerException: &lt;/b&gt;" + ex.InnerException.ToString() +
                                    "&lt;br /&gt;&lt;br /&gt;\r\n";
                lblResponse.Text += "&lt;b&gt;StackTrace: &lt;/b&gt;" + ex.StackTrace.ToString() +
                                    "&lt;br /&gt;&lt;br /&gt;\r\n";
            }
        }

        protected void User_Src_SelectedIndexChanged(object sender, EventArgs e)
        {
            string query = "SELECT [Name], [UserQueryId] FROM [UserQueryBase] WHERE ([OwningUser] = '"+
                           User_Src.SelectedValue+"') ORDER BY [Name]";

            // Pull the crm_db connection string for the webconfig. (you could just replace this with
            // your connection string.

            SqlDataAdapter da = new SqlDataAdapter(query,
			   WebConfigurationManager.ConnectionStrings["crm_db"].ToString());

            DataSet ds = new DataSet();
            da.Fill(ds);

            QueueList.DataSource = ds.Tables[0].DefaultView;
            QueueList.DataTextField = "Name";
            QueueList.DataValueField = "UserQueryId";
            QueueList.DataBind();
            upnQueries.Update();
        }

        protected void Assign_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (ListItem li in QueueList.Items)
                {
                    if (li.Selected)
                    {
                        lblResponse.Text += "Item: " + li.Value + " to: ";
                        lblResponse.Text += User_Target.SelectedValue + "&lt;br /&gt;";
                        AssignUserQuery(li.Value, User_Target.SelectedValue);
                    }
                }
                lblResponse.Text += "&lt;br /&gt;Moved Successfully";
                User_Src_SelectedIndexChanged(sender, e);
            }
            catch (Exception ex)
            {
                lblResponse.Text += ex.ToString() + "&lt; br/&gt;";
                lblResponse.Text += "Please report this error to internal systems.&lt;br /&gt;";
            }
        }

    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2009/02/04/crm-4-userquery-privileges-for-system-administrators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

