<?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; forms</title>
	<atom:link href="http://mscrmblogger.com/tag/forms/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>InfoPath to CRM: Accepting Emailed InfoPath Forms</title>
		<link>http://mscrmblogger.com/2011/11/21/infopath-to-crm-accepting-emailed-infopath-forms/</link>
		<comments>http://mscrmblogger.com/2011/11/21/infopath-to-crm-accepting-emailed-infopath-forms/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 19:05:51 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[InfoPath]]></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[plugin]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Web Resource]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=889</guid>
		<description><![CDATA[Everybody loves to use InfoPath forms.  And let's face it, we all wish we could just take them and put them into CRM.  This post delves into how I integrated InfoPath &#38; CRM to dynamically allow InfoPath forms received by email into CRM records.  It is still <i>under development</i>, but the source code has been partially tested and works.]]></description>
			<content:encoded><![CDATA[<p>Everybody loves to use InfoPath forms.  And let&#8217;s face it, we all wish we could just take them and put them into CRM.  What I&#8217;ve written is a simple way to do that without the hassle of figuring out how to bind the InfoPath form schema to a custom WCF service.  It still doesn&#8217;t do everything I want it to, but it works, so I figured I&#8217;d go ahead and put it out there for everyone to look at, play with, and even use.</p>
<p>If you are interested in this solution, you can download the following:</p>
<ul>
<li><a href='http://mscrmblogger.com/wp-content/uploads/2011/11/InfoPath_1_0_0_0_managed.zip'>Managed Solution</a> (this is the only thing you need)</li>
<li><a href='http://mscrmblogger.com/wp-content/uploads/2011/11/InfoPath_1_0_0_0.zip'>Unmanaged Solution</a> (in case you want to modify mine, like add grid support, it is on my to-do list)</li>
<li><a href='http://mscrmblogger.com/wp-content/uploads/2011/11/InfoPath4CRMSourceCode.zip'>Source Code</a> (this is in case you would prefer to use a WCF service or if you just want to play around with my code)</li>
</ul>
<p>Once you&#8217;ve installed the managed solution, you&#8217;ll need to do the following to create / setup an InfoPath form:</p>
<ol>
<li>
<p>For this particular InfoPath integration, you need to create InfoPath Forms that mirror a CRM Entity.<br />
<strong>Note: </strong><em>You can always create a new entity for the form data.</em></p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC13.png" alt=""/></p>
</li>
<li>
<p>Rename the default form Group to the name of the entity (ex: Contact)</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC23.png" alt=""/></p>
</li>
<li>
<p>Inside CRM create the InfoPath form (it is an entity included in the solution), select the entity and save the form.
</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC31.png" alt=""/></p>
</li>
<li>
<p>Once it has been saved, you can copy the ID using the &#8220;Copy ID&#8221; link in the header.<br />
<br /><strong>Note: </strong>If you do not select the <em>Allow Any CRM Field </em>checkbox, you will need to add the individual Fields, which can be found in the left navigation.</p>
</li>
<li>
<p>In the InfoPath Form Designer, add a field named SubmissionCode with the Default Value as the ID you just copied.<br />
<br /><b>Note:</b> Using the submission code allows us to check and see if the form is valid, active, and allowed.</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/submissioncode.png" alt=""/></p>
</li>
<li>
<p>Add a field for each of the fields in CRM that you want to be available, selecting the appropriate data type.<br />
<br /><b>Note:</b> Unfortunately I have not had the time to test the fields and have been using the checkbox on the infopath form record to enable any/all CRM fields.  However, I did not want to delay releasing the code and information as it currently is.  If someone identifies a problem with this or any other section of the code, I&#8217;ll be happy to look into it and work on resolving the issue.</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC53.png" alt=""/></p>
</li>
<li>
<p>Layout the fields on the form, then click File &gt; Submit Options &gt; To Email</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC63.png" alt=""/></p>
</li>
<li>
<p>Enter the Queue email or where you want new forms to be submitted.</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC73.png" alt=""/></p>
</li>
<li>
<p>Click Next.</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC83.png" alt=""/></p>
</li>
<li>
<p>Click Finish.</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC93.png" alt=""/></p>
</li>
<li>Save and close the form designer.</li>
<li>
<p>Open the form and test submission.</p>
<p style="text-align: center"><img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC103.png" alt=""/></p>
</li>
</ol>
<p>Once the email comes into CRM, the process of reading the form is easy; you just open it up and click the <img src="http://mscrmblogger.com/wp-content/uploads/2011/11/112111_1905_InfoPathtoC113.png" alt=""/> Import InfoPath button on the ribbon.</p>
<p>Usually I would post the source-code and comment on how it works in great detail, but this time, it really depends on which component.  There is a plugin and WCF service written in C# as well as two Jscript files, one for the buttons and one for the InfoPath form inside CRM that creates a drop-down of the entities in CRM.  I would suggest downloading the unmanaged solution and source-code if you want to delve into those items.</p>
<p>Now, for complex situations or form conversions, binding the InfoPath schema is the way to go.  Using that method (the one described in detail on <a href="http://blogs.msdn.com/b/philoj/archive/2005/11/08/490200.aspx">Philo&#8217;s Weblog</a>) you can import the InfoPath form schema into Visual Studio:</p>
<ol>
<li>Create an InfoPath form and lay it out the way you want it.
</li>
<li>Extract the form files (File | Extract Form Files) to a location you can find later.
</li>
<li>Close the InfoPath form designer.
</li>
<li>Open the Visual Studio command prompt.
</li>
<li>Change to the directory where you extracted the files<br /><strong>cd c:\myinfopathfiles<br />
</strong></li>
<li>Run xsd against the myschema.xsd in that directory, and specify the namespace you would like to use.<br /><strong>Note: </strong>My WCF namespace is CrmInfoPathService and my plugin namespace is InfoPathPlugin.<br /><strong>xsd.exe myschema.xsd /classes /l:cs /n:InfoPathPlugin<br />
</strong></li>
<li>Then you can deserialize the xml into the object and store it in CRM or any other system using the logic embedded in your code.</li>
</ol>
<p>The key point to my solution was not to do something that everyone does on occasion, but to make something so that I can leverage it in the future and not have to create a new integration every time I wanted to leverage a new form.  Now, on that note, here are the list of things that if you delve into, I&#8217;d like to know, a.k.a. my to-do list for this project:
</p>
<ul>
<li>Add a button onto the grid for activities</li>
<li>Create a way to handle child entities.</li>
<li>Modify the plugin/WCF code to link the created entities to the form email using connections.</li>
<li>Change the button on the form to monitor for the results (success/failure) and report back to the user.</li>
<li><i>Any great ideas my readers think should be added!</i></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/11/21/infopath-to-crm-accepting-emailed-infopath-forms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CRM 2011: Slider Form Control Web Resource</title>
		<link>http://mscrmblogger.com/2011/10/04/crmslider/</link>
		<comments>http://mscrmblogger.com/2011/10/04/crmslider/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 20:23:11 +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[Scripts]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[CRM Online]]></category>
		<category><![CDATA[crm2011]]></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[script]]></category>
		<category><![CDATA[slidebar]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[Web Resource]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=804</guid>
		<description><![CDATA[Here is another web-resource html control to expand your CRM forms.  It is a slider control for CRM with step control.  It provides a graphical way to slide a value up and down.]]></description>
			<content:encoded><![CDATA[<p>Here is another web-resource html control to expand your CRM forms.  It is a slider control for CRM with step control.</p>
<p>Below is an example of the slider control in action, and you can <a href='http://mscrmblogger.com/wp-content/uploads/2011/10/SliderFormControl_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, just like the <a href="http://mscrmblogger.com/2011/09/20/crm-2011-star-rating-control/" target="_blank">star rating control</a>).  If you want the unmanaged solution you can download it <a href='http://mscrmblogger.com/wp-content/uploads/2011/10/SliderFormControl_1_0.zip'>here</a>.</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/10/slider2.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/10/slider2.png" alt="" title="Slider Form Control" width="816" height="360" class="aligncenter size-full wp-image-806" /></a></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 slider value and put it on the form, but uncheck the visible box.</p>
<p>Add the Web-Resource to the form, check the box to <strong>display the label on the form</strong>, and then enter your parameters.  I like using a pipe separator.  The available parameters are:</p>
<ul>
<li><strong>min</strong>: minimum value</li>
<li><strong>max</strong>: maximum value</li>
<li><strong>field</strong>: the CRM field to store the value in</li>
<li><strong>step</strong>: the step increase</li>
<li><strong>stepoverride</strong>: don&#8217;t use the step when a value is manually entered</li>
</ul>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/10/Slider_Score_Resource1.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/10/Slider_Score_Resource1.png" alt="" title="Slider_Score_Resource1" width="486" height="615" class="aligncenter size-full wp-image-825" /></a></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 uncheck the box to <strong>display the border</strong>.</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/10/Slider_Score_Resource2.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/10/Slider_Score_Resource2.png" alt="" title="Slider_Score_Resource2" width="486" height="622" class="aligncenter size-full wp-image-826" /></a></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><a href="http://mscrmblogger.com/wp-content/uploads/2011/10/Score-Field.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/10/Score-Field.png" alt="" title="Score Field" width="544" height="251" class="aligncenter size-full wp-image-828" /></a></p>
<p>Here is the code for the slider control HTML web resource.</p>
<pre name="code" class="html">
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Slider Control&lt;/title&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
var Settings = {};
Settings.Min = 0;
Settings.Max = 100;
Settings.Step = 5;
Settings.Value = 50;
Settings.Field = null;
Settings.AllowStepOverride = false;

var Slider = {};
Slider.Drag = false;

Slider.Initialize = function Slider(id,min,max,step,value,onchange) {
  Settings.Min = min;
  Settings.Max = max;
  Settings.Step = step;
  Slider.Value = value;

  var ihtml = &quot;&quot;;
  ihtml += &quot;&lt;table width='100%' cellspacing='0' cellpadding='0'&gt;&lt;tr&gt;&quot;;
  ihtml += &quot;&lt;td class='left-bracket'&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='value'&gt;&quot;;
  ihtml += &quot;&lt;input class='value' id='value' type='text' onchange='Slider.SetValue();' /&gt;&quot;;
  ihtml += &quot;&lt;/td&gt;&lt;td class='right-bracket'&gt;&amp;nbsp;&lt;/td&gt;&quot;;
  ihtml += &quot;&lt;td class='slider-left' /&gt;&lt;td class='slider-area' id='&quot;+id+&quot;-area' &gt;&quot;;
  ihtml += &quot;&lt;div id='&quot;+id+&quot;-selector' class='slider-selector' /&gt;&lt;/td&gt;&quot;
  ihtml += &quot;&lt;td class=&#39;slider-right&#39; /&gt;&lt;/tr&gt;&lt;/td&gt;&lt;/table&gt;&quot;;
  var p = document.getElementById(id);
  p.innerHTML = ihtml;

  Slider.Element = document.getElementById(id+&quot;-area&quot;);
  Slider.Element.attachEvent(&quot;onmousedown&quot;,Slider.OnMouseClick);

  Slider.Id = id;
  Slider.Selector = document.getElementById(id+&quot;-selector&quot;);
  Slider.Selector.attachEvent(&quot;onmousedown&quot;,Slider.OnMouseDown);
  Slider.Selector.attachEvent(&quot;onmousemove&quot;,Slider.OnMouseMove);
  Slider.Selector.attachEvent(&quot;onmouseup&quot;,Slider.OnMouseUp);
  Slider.Selector.attachEvent(&quot;onmouseleave&quot;,Slider.OnMouseUp);

  Slider.UpdatePosition();
}

Slider.SliderRatio = function() {
  var num =  Settings.Max - Settings.Min;
  var den = parseFloat(Slider.Element.offsetWidth)-parseFloat(Slider.Selector.offsetWidth);
  return den/num;
};

Slider.UpdatePosition = function () {
  Slider.Position = Math.round(Slider.Value*Slider.SliderRatio());
  Slider.SetPosition();
};

Slider.OnMouseClick = function(e) {
  Slider.Position = e.clientX - (8+Slider.Selector.offsetLeft-parseInt(Slider.Selector.style.left.replace(&quot;px&quot;,&quot;&quot;)));
  Slider.SetPosition();
  Slider.OnChange(Slider.Value);
}

Slider.SetPosition = function() {
  if (Slider.Position&lt;0) Slider.Position = 0;
  var max = Slider.Element.offsetWidth-Slider.Selector.offsetWidth;
  if (Slider.Position&gt;max) Slider.Position = max;

  Slider.Selector.style.left = Slider.Position + &quot;px&quot;;

  var i = Math.round(Slider.Position/Slider.SliderRatio());
  i = (Math.floor(i/Settings.Step))*Settings.Step;

  Slider.Value = i;

  var val = document.getElementById('value');
  if (val===null) return;
  val.value = i;
}

Slider.SetValue = function() {
  var val = document.getElementById('value');
  if (Settings.AllowStepOverride) {
    Slider.Value = val.value;
  } else {
    Slider.Value = Math.round(val.value/Settings.Step)*Settings.Step;
  }
  if (Slider.Value&lt;Settings.Min) Slider.Value = Settings.Min;
  if (Slider.Value&gt;Settings.Max) Slider.Value = Settings.Max;
  Slider.UpdatePosition();
}

Slider.OnMouseDown = function(e)  {
  Slider.Drag = true;
}

Slider.OnMouseMove = function(e) {
  if (Slider.Drag) {
    Slider.Position = e.clientX - (8+Slider.Selector.offsetLeft-parseInt(Slider.Selector.style.left.replace(&quot;px&quot;,&quot;&quot;)));
    Slider.SetPosition();
  }
};

Slider.OnMouseUp = function(e) {
  if (Slider.Drag) {
    Slider.Drag = false;
    Slider.OnChange(Slider.Value);
  }
};

Slider.OnChange = function(val) {
  parent.Xrm.Page.data.entity.attributes.get(Settings.Field).setValue(val);
};

var InitializeSlider = function() {
  var data = WebResource.GetDataParams();
  var sliderBox = document.getElementById(&quot;sliderBox&quot;);

  for (var i in data)
  {
    switch (data[i][0].toLowerCase())
	{
	  case 'min': Settings.Min = parseInt(data[i][1],10); break;
	  case 'max': Settings.Max = parseInt(data[i][1],10); break;
	  case 'step': Settings.Step = parseInt(data[i][1],10); break;
	  case 'value': Settings.Value = parseInt(data[i][1],10); break;
	  case 'field': Settings.Field = data[i][1]; break;
	  case 'stepoverride': Settings.AllowStepOverride = (data[i][1]=='true'); break;
	  default:break;
	}
  }

  Slider.Initialize(&quot;slider&quot;,Settings.Min,Settings.Max,Settings.Step,Settings.Value,null)

  if (Settings.Field!=null) {
    var val = parent.Xrm.Page.data.entity.attributes.get(Settings.Field).getValue();
	if (val!==null) {
	  var num = parseInt(val);
	  Slider.Value = num;
	  Slider.UpdatePosition();
	}
  }
};

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;
html, body {
  padding: 0px;
  margin: 0px;
  border: 0px;
  background-color: rgb(246, 248, 250);
  overflow:hidden;
}
.slider-left, .slider-area, .slider-right {
  background-image:url(img/bar.png);
  background-repeat:repeat-x;
  height:17px;
  padding:0px;
  margin:0px;
  cursor:hand;
}
.slider-left, .slider-right {
  width: 7px;
}
div.slider-selector {
  background-image:url(img/selector.png);
  background-repeat:no-repeat;
  width:15px;
  height:17px;
  position: relative;
  cursor:hand;
}
td.left-bracket, td.right-bracket {
  background-repeat:no-repeat;
  height:17px;
  width:6px;
  display:inline;
}
td.left-bracket {
  background-image:url(img/left_bracket.png);

}
td.right-bracket {
  background-image:url(img/right_bracket.png);
}
td.value {
  background-image:url(img/val_bk.png);
  background-repeat:repeat-x;
  height:17px;
  width:30px;
}
input.value {
  border: none;
  font:11px segoe ui,tahoma,arial;
  height:17px;
  width:30px;
  background-color:transparent;
  vertical-align:top;
  padding-top:1px;
  text-align:center;
}
  &lt;/style&gt;
&lt;/head&gt;
&lt;body onload=&quot;InitializeSlider();&quot;&gt;
&lt;div id=&quot;slider&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Thanks to <a href="http://manishmistry.wordpress.com" target="_blank">Manish Mistry</a> comment on my star control for refreshing the iframe when you change the value, you could do the same on this control.  However, you could also just set the value and update the position. The only reason I get the control&#8217;s object and it&#8217;s id is because I&#8217;m not 100% sure the id will always match, even though all my tests indicate it does.</p>
<pre name="code" class="javascript">
var control = Xrm.Page.ui.controls.get('WebResource_Score');
var id      = control.getObject().id;
var frame   = document.frames[id];
frame.Slider.Value = 50;
frame.Slider.UpdatePosition();
</pre>
<p>One of my TODO&#8217;s is to join my web resources HTML form controls into a single library once I have enough of them so that people can leverage them in an easier manner.  If anyone has any ideas for custom controls for Dynamics CRM, let me know and I&#8217;ll see if I can build it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/10/04/crmslider/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<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>Adding ImageTools to the CRM Attachment Image for CRM 2011</title>
		<link>http://mscrmblogger.com/2011/09/15/adding-imagetools-to-the-crm-attachment-image-for-crm-2011/</link>
		<comments>http://mscrmblogger.com/2011/09/15/adding-imagetools-to-the-crm-attachment-image-for-crm-2011/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 16:31:40 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[CodePlex]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[CRM Online]]></category>
		<category><![CDATA[crm sdk]]></category>
		<category><![CDATA[crm2011]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[gif]]></category>
		<category><![CDATA[ImageTools]]></category>
		<category><![CDATA[Microsoft Dynamics]]></category>
		<category><![CDATA[microsoft dynamics crm]]></category>
		<category><![CDATA[Microsoft Dynamics CRM 2011]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[Web Resource]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=735</guid>
		<description><![CDATA[<p>An update to the Silverlight control on codeplex at <a href="http://crmattachmentimage.codeplex.com">CRMAttachmentImage.CodePlex.com</a> for adding images to any entity form in CRM 2011 to now support GIFs and WebCam capture using ImageTools for Silverlight.</p>]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://mscrmblogger.com/2011/05/10/crm-attachment-image-for-crm-2011-entities/">previous post</a> I wrote about a control I posted to <a href="http://crmattachmentimage.codeplex.com" target="_blank">codeplex</a> that I used in my demos, a <a href="http://crmattachmentimage.codeplex.com" target="_blank">CRM Attachment Image Control</a>.</p>
<p>It stored the images in the notes (still does &#8211; and currently does not have an option for storing elsewhere&#8230;).  I still have not figured out how to put buttons on the ribbon that can fire the upload control, etc.  Although, I recently found out that Marco Amoedo (blog: <a href="http://marcoamoedo.com">marcoamoedo.com</a>, twitter: <a target="_blank" href="http://twitter.com/#!/marcoamoedo" target="_blank">marcoamoedo</a>) had leveraged the <a href="http://imagetools.codeplex.com" target="_blank">ImageTools for Silverlight</a> to add WebCam support and I was already starting to play with it to add Gif support.  I was able to work with him to get his modifications and add gif support.   Now you have even more useful features that you can enable with a simple configuration change and a new silverlight web-resource.</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/09/Contact-Photo-WebCam.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/Contact-Photo-WebCam.png" alt="" title="Contact Photo WebCam" width="509" height="383" class="aligncenter size-full wp-image-745" /></a></p>
<p>Now, if you look in the bottom right, there is a webcam button next to the upload button that allows you to take a picture instead of uploading one.  When you try and take the picture you will receive the following request for access.</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/09/Silverlight-Camera-Access.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/Silverlight-Camera-Access.png" alt="" title="Silverlight Camera Access" width="564" height="217" class="aligncenter size-full wp-image-747" /></a></p>
<p>So you may be asking: what is <a href="http://imagetools.codeplex.com" target="_blank">ImageTools for Silverlight</a>? where did it come from?, and why are you using it?  The answers are simple. According to the codeplex page for the <a href="http://imagetools.codeplex.com" target="_blank">ImageTools for Silverlight</a>, it is &quot;a library, which provides additional functionality for loading, saving and [manipulating] images from different sources and with different formats.&#038;quot  The reason to use it is simple, it is open-source, and it&#8217;s license allows me to use it (it is realeased under Ms-PL &#8211; the same license as my control on codeplex).</p>
<p>If you already use the <a href="http://crmattachmentimage.codeplex.com" target="_blank">CRM Attachment Image</a>, you can just overwrite your xap file with the one from <a href="http://crmattachmentimage.codeplex.com" target="_blank">codeplex</a>, but you will still need to edit the properties of the web-resource on your form to include <b>|webcam=true</b>.  The new example syntax is:</p>
<pre>field=new_imageattachmentid|subject='Contact''s Image'|prefix='img-'|webcam=true</pre>
<p>So a special thanks to <a href="http://marcoamoedo.com">Marco</a> for his help, this is a great change that I think a lot of people will be able to use.</p>
<p>If you need assistance in setting up the image control, I have it documented on codeplex, but here is a simple set of directions that work at the time of this article bieng posted:</p>
<ol>
<li>Create a solution</li>
<li>Upload the xap as a web-resource</li>
<li>Add your entity to the solution, and create a new text field on the entity that is 50 characters long, not searchable, preferably called something like attachmentid or savedattachmentid &#8211; it will be used to store the annotationid or the note that stores the attached image.</li>
<li>Add the field to the form and make it not visible.</li>
<li>Add the Web-Resource to the form
<ul>
<li>Check the checkbox to pass the id and type, etc.</li>
<li>In the parameters add the fields and their values seperated by a pipe |</li>
</ul>
</li>
<li>Save and publish the form.</li>
<li>Test it!</li>
</ol>
<p>The example config for the web-resource is before the instructions, and are very useful because you can just copy them and change the field <b>new_imageattachmentid</b> to your field name and it should work.  There are a number of fields available to you if you want to change how the control functions, they are documented on codeplex, and they are:</p>
<ul>
<li>field &#8211; The name of the field you are using to store the annotationid of the attachment. It is required, and the field MUST BE ON THE FORM (it does not need to be visible). </li>
<li>subject &#8211; The subject for attachments &#8211; the following substitutions are available (%s will be replaced with the name of the file )</li>
<li>prefix &#8211; The prefix for all attachment images (this is used to filter the results, etc)</li>
<li>hidebuttons &#8211; Used to hide the buttons that are in the silverlight control so that you can use the ribbon to control the application</li>
<li>savefirst &#8211; Used to set the message that is displayed on a form that is in Create Mode</li>
<li>webcam &#8211; Set to true if you want to enable the webcam it is not currently tide to hidebuttons</li>
</ul>
<hr />
<p style="color:#c69"><i>I added the following parameters at Bill&#8217;s request (Thanks Bill):</i></p>
<ul style="color:#f9f">
<li><b>max-width</b>: maximum width for all images</li>
<li><b>max-height</b>: maximum height for all images</li>
<li><b>max-webcam-width</b>: maximum webcam image width, overrides max-width for web-cam images</li>
<li><b>max-webcam-height</b>: maximum webcam image height, overrides max-height for web-cam images</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/09/15/adding-imagetools-to-the-crm-attachment-image-for-crm-2011/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Use Microsoft Translator to translate text in CRM (Button on Ribbon)</title>
		<link>http://mscrmblogger.com/2011/09/14/use-microsoft-translator-to-translate-text-in-crm-button-on-ribbon/</link>
		<comments>http://mscrmblogger.com/2011/09/14/use-microsoft-translator-to-translate-text-in-crm-button-on-ribbon/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 15:58:19 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Addons]]></category>
		<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[General API Usage]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[bing translator]]></category>
		<category><![CDATA[cases]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics crm]]></category>
		<category><![CDATA[Microsoft Dynamics CRM 2011]]></category>
		<category><![CDATA[microsoft translator]]></category>
		<category><![CDATA[ribbon]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[translate]]></category>
		<category><![CDATA[Web Resource]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=695</guid>
		<description><![CDATA[Ever want to translate text from within CRM?  This solution adds a button on the ribbon to translate text from other languages to english using the Microsoft Bing Translator.]]></description>
			<content:encoded><![CDATA[<p>Do you have issues receiving request or information in various languages and need it translated to English (or another language)?  I found the need to translate something from any language to english just so when someone submits a case or puts some notes in another language it can quickly be translated.</p>
<p>Here is what my bing translator integration looks like.</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/09/translator-screenshot.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/translator-screenshot.png" alt="" title="Implemented Translator Screenshot" width="730" height="671" class="aligncenter size-full wp-image-706" /></a></p>
<p>You can download an unmanaged solution to implement the bing translator for cases, letters, tasks, and emails, you can download it here: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0.zip'>Translate_1_0.zip</a>.  It will not modify your forms, but if you have unmanaged ribbon buttons on those entities, it will remove them.  So to avoid that problem you can install <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-ImageJS.zip'>the unmanaged solution with the JScript (that you need to edit to set your bing api key) and the images</a>, and then follow the RibbonDiff guide in the SDK to add the buttons, or install <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-Ribbon-Managed.zip'>the managed solution</a> to add the button to the ribbons for cases, letters, tasks, and emails.</p>
<p>To start, I created a JScript file to include as a web-resource that I could leverage when a button is clicked on the ribbon.  This JScript file utilizes the Bing Translation WebServices to translate text.</p>
<p><i><b>YOU WILL NEED TO EDIT THE JSCRIPT FILE AND CHANGE &#8216;YOUR API KEY GOES HERE&#8217; TO CONTAIN YOUR API KEY.</b></i></p>
<pre name="code" class="javascript">
var bing = {};
bing.popup = {};
bing.language = {};

bing.appId = 'YOUR API KEY GOES HERE';
bing.language.text = '';
bing.language.from = '';
bing.language.to = 'en';

bing.language.detect = function (text,oncomplete)
{
  var src = &quot;https://api.microsofttranslator.com/V2/Ajax.svc/Detect?oncomplete=&quot; +
      oncomplete + &quot;&amp;appId=&quot;+ bing.appId + &quot;&amp;text=&quot; + text;
  var s = document.createElement(&quot;script&quot;);
  s.src = src;
  s.id = &quot;bingdetect&quot;;
  document.getElementsByTagName(&quot;head&quot;)[0].appendChild(s);
}

bing.language.translate = function(from,to,text,oncomplete)
{
  var src = &quot;https://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=&quot; +
      oncomplete + &quot;&amp;appId=&quot; + bing.appId + &quot;&amp;from=&quot; + from +
      &quot;&amp;to=&quot; + to + &quot;&amp;text=&quot; + text;

  var s = document.createElement(&quot;script&quot;);
  s.src = src;
  s.id = &quot;bingtranslate&quot;;
  document.getElementsByTagName(&quot;head&quot;)[0].appendChild(s);
}

bing.popup.show = function(text)
{
  var idiv = document.createElement('div');
  idiv.id = &quot;bingtext&quot;;
  idiv.style.height = &quot;265px&quot;;
  idiv.style.width = &quot;306px&quot;;
  idiv.style.align = &quot;left&quot;;
  idiv.style.textAlign = &quot;left&quot;;
  idiv.style.backgroundColor = &quot;white&quot;;
  idiv.style.overflow = &quot;auto&quot;;
  idiv.style.padding = &quot;2px&quot;;
  idiv.style.margin = &quot;2px&quot;;
  idiv.style.border = &quot;1px solid black&quot;;
  idiv.innerHTML =  &quot;&lt;p&gt;&quot;+text+&quot;&lt;/p&gt;&quot;;

  var iurl = Xrm.Page.context.getServerUrl();
  iurl += &quot;WebResources/tran_img/translatelogo.gif&quot;;

  var img = document.createElement('img');
  img.src = iurl;

  var div = document.createElement('div');
  div.id = &quot;bingpopup&quot;;
  div.appendChild(img);
  div.appendChild(idiv);
  div.innerHTML += &quot;&lt;button style='text-align:center;width:60px;' onclick='bing.popup.copy();'&gt;Copy&lt;/button&gt;&amp;nbsp;&amp;nbsp;&quot;;
  div.innerHTML += &quot;&lt;button style='text-align:center;width:60px;' onclick='bing.popup.hide();'&gt;Close&lt;/button&gt;&quot;;
  div.style.position = &quot;absolute&quot;;
  div.style.backgroundColor = &quot;#20415F&quot;;
  div.style.border=&quot;1px solid black&quot;;
  div.style.left = &quot;50%&quot;;
  div.style.top = &quot;50%&quot;;
  div.style.color = &quot;black&quot;;
  div.style.padding = &quot;5px&quot;;
  div.style.width = &quot;320px&quot;;
  div.style.height = &quot;340px&quot;;
  div.style.marginLeft = &quot;-160px&quot;;
  div.style.marginTop = &quot;-170px&quot;;
  div.setAttribute(&quot;align&quot;,&quot;center&quot;);
  document.getElementsByTagName(&quot;body&quot;)[0].appendChild(div);
}

bing.popup.hide = function()
{
  var deleteElement = function(id) {
    var el = document.getElementById(id);
    el.parentNode.removeChild(el);
  }

  deleteElement(&quot;bingpopup&quot;);
  deleteElement(&quot;bingdetect&quot;);
  deleteElement(&quot;bingtranslate&quot;);
}

bing.popup.copy = function()
{
  var el = document.getElementById('bingtext');

  if (window.clipboardData &amp;&amp; window.clipboardData.setData)
  {
    window.clipboardData.setData(&quot;Text&quot;, el.innerText);
  }
}

bing.getSelectedText = function (p)
{
  if (p.getSelection)
  {
    text = p.getSelection();
  }
  else if (p.selection)
  {
    text = p.selection.createRange().text;
  }
  return text;
}

// get current control
bing.language.toolbarClick = function (ctrl)
{
  var text = '';
  if (window.getSelection)
  {
    text = window.getSelection();
  }
  else {
    text = bing.getSelectedText(document);
  }

  if (text==null || text=='') {
    if (ctrl==null) {
      ctrl = Xrm.Page.ui.getCurrentControl();
    }

    var entityName = Xrm.Page.data.entity.getEntityName();
    if (ctrl==null &amp;&amp; entityName.match(/letter|email|task/)) {
      ctrl = Xrm.Page.ui.controls.get('description');
    }

    if (ctrl==null) {
      alert('Please highlight the text to translate.');
      return;
    }

    if (ctrl.getControlType()!=&quot;standard&quot;) {
      return; // only standard
    }

    if (ctrl.getName()==&quot;notescontrol&quot;) {
      text = bing.getSelectedText(document.frames['notescontrol'].document);
      if (text==null || text == &quot;&quot;) {
        alert('Please highlight the text to translate.');
      }
    }

    if (text == null || text == &quot;&quot;) {
      var attr = ctrl.getAttribute();
      if (attr!=null) {
        var t = attr.getAttributeType();
        if (t.match(/string|memo/))
        {
          text = attr.getValue();
        }
      }
    }
  }

  if (text == null || text == &quot;&quot;) {
    // Nothing to translate
    return;
  }  

  text = encodeURIComponent(text);
  bing.language.text = text;

  bing.language.from = '';
  bing.language.detect(text,&quot;translate&quot;);
}

window.translate = function (response)
{
  bing.language.from = response;
  bing.language.translate(bing.language.from,bing.language.to,bing.language.text,&quot;translated&quot;);
}

window.translated = function (response)
{
  bing.popup.show(response);
}
</pre>
<p>The JScript uses the Bing Translate logo image (WebResources/tran_img/translatelogo.gif &#8211; you may need to change the path in the JScript):</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/09/bingtranslatelogo.gif"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/bingtranslatelogo.gif" alt="" title="Bing Translator Logo" width="145" height="39" class="aligncenter size-full wp-image-700" /></a></p>
<p>I added some images for Microsoft Translate button images:</p>
<p><center></p>
<table style="background-color:white;padding:20px;color:black">
<tr>
<td style="border:1px solid black;height:65px;padding:7px;">
<a href="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_16x16.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_16x16.png" alt="" title="tran_icontranslate_16x16" width="16" height="16" /></a><br />16&#215;16 image<br />tran_icontranslate_16x16.png
</td>
<td style="width:20px" />
<td style="border:1px solid black;height:65px;padding:7px;">
<a href="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_32x32.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_32x32.png" alt="" title="tran_icontranslate_32x32" width="32" height="32" /></a><br />32&#215;32 image<br />tran_icontranslate_32x32.png
</td>
</tr>
</table>
<p>
</center></p>
<p>Then I added the buttons to the ribbons on the entities I wanted to have bing translation capabilities by following the <a href="http://msdn.microsoft.com/en-us/library/gg334341.aspx">SDK guidelines to add a button</a>.  Here is the RibbonDiffXml for a case.  You can follow the guide to change it to be on different entities.</p>
<pre name="code" class="xml">
&lt;RibbonDiffXml&gt;
  &lt;CustomActions&gt;
    &lt;CustomAction Id=&quot;bing.incident.form.Bing.CustomAction&quot;
                  Location=&quot;Mscrm.Form.incident.MainTab.Groups._children&quot;
                  Sequence=&quot;110&quot;&gt;
    &lt;CommandUIDefinition&gt;
      &lt;Group Id=&quot;bing.incident.form.Bing.Group&quot;
             Command=&quot;bing.incident.form.Bing.Command&quot;
             Title=&quot;$LocLabels:bing.incident.Bing.Title&quot;
             Sequence=&quot;39&quot;
             Template=&quot;Mscrm.Templates.Flexible2&quot;
             Image32by32Popup=&quot;$webresource:tran_icon/translate_32x32.png&quot;&gt;
      &lt;Controls Id=&quot;bing.incident.form.Bing.Controls&quot;&gt;
        &lt;Button Id=&quot;bing.incident.form.Bing.Button.BingTranslator&quot;
                Command=&quot;bing.incident.Bing.Button.BingTranslator.Command&quot;
                Sequence=&quot;10&quot;
                LabelText=&quot;$LocLabels:bing.incident.Bing.Button.BingTranslator.LabelText&quot;
                ToolTipTitle=&quot;$LocLabels:bing.incident.Bing.Button.BingTranslator.LabelText&quot;
                ToolTipDescription=&quot;$LocLabels:bing.incident.Bing.Button.BingTranslator.Description&quot;
                TemplateAlias=&quot;isv&quot;
                Image16by16=&quot;$webresource:tran_icon/translate_16x16.png&quot;
                Image32by32=&quot;$webresource:tran_icon/translate_32x32.png&quot; /&gt;
      &lt;/Controls&gt;
      &lt;/Group&gt;
    &lt;/CommandUIDefinition&gt;
    &lt;/CustomAction&gt;
    &lt;CustomAction Id=&quot;bing.incident.form.Bing.Popup.CustomAction&quot;
                  Location=&quot;Mscrm.Form.incident.MainTab.Scaling._children&quot;
                  Sequence=&quot;140&quot;&gt;
    &lt;CommandUIDefinition&gt;
      &lt;Scale Id=&quot;bing.incident.form.Bing.Popup.1&quot;
             GroupId=&quot;bing.incident.form.Bing.Group&quot;
             Sequence=&quot;85&quot;
             Size=&quot;Popup&quot; /&gt;
    &lt;/CommandUIDefinition&gt;
    &lt;/CustomAction&gt;
    &lt;CustomAction Id=&quot;bing.incident.form.Bing.MaxSize.CustomAction&quot;
                  Location=&quot;Mscrm.Form.incident.MainTab.Scaling._children&quot;
                  Sequence=&quot;120&quot;&gt;
    &lt;CommandUIDefinition&gt;
      &lt;MaxSize Id=&quot;bing.incident.form.Bing.MaxSize&quot;
               GroupId=&quot;bing.incident.form.Bing.Group&quot;
               Sequence=&quot;21&quot;
               Size=&quot;LargeLarge&quot; /&gt;
    &lt;/CommandUIDefinition&gt;
    &lt;/CustomAction&gt;
  &lt;/CustomActions&gt;
  &lt;Templates&gt;
    &lt;RibbonTemplates Id=&quot;Mscrm.Templates&quot;&gt;&lt;/RibbonTemplates&gt;
  &lt;/Templates&gt;
  &lt;CommandDefinitions&gt;
    &lt;CommandDefinition Id=&quot;bing.incident.Bing.Button.BingTranslator.Command&quot;&gt;
    &lt;EnableRules /&gt;
    &lt;DisplayRules /&gt;
    &lt;Actions&gt;
      &lt;JavaScriptFunction Library=&quot;$webresource:tran_js/bing.translate.js&quot;
                          FunctionName=&quot;bing.language.toolbarClick&quot;&gt;
      &lt;CrmParameter Value=&quot;SelectedControl&quot; /&gt;
      &lt;/JavaScriptFunction&gt;
    &lt;/Actions&gt;
    &lt;/CommandDefinition&gt;
    &lt;CommandDefinition Id=&quot;bing.incident.form.Bing.Command&quot;&gt;
    &lt;EnableRules&gt;&lt;/EnableRules&gt;
    &lt;DisplayRules /&gt;
    &lt;Actions /&gt;
    &lt;/CommandDefinition&gt;
  &lt;/CommandDefinitions&gt;
  &lt;RuleDefinitions&gt;
    &lt;TabDisplayRules /&gt;
    &lt;DisplayRules /&gt;
    &lt;EnableRules /&gt;
  &lt;/RuleDefinitions&gt;
  &lt;LocLabels&gt;
    &lt;LocLabel Id=&quot;bing.incident.Bing.Title&quot;&gt;
    &lt;Titles&gt;
      &lt;Title languagecode=&quot;1033&quot;
             description=&quot;Bing&quot; /&gt;
    &lt;/Titles&gt;
    &lt;/LocLabel&gt;
    &lt;LocLabel Id=&quot;bing.incident.Bing.Button.BingTranslator.LabelText&quot;&gt;
    &lt;Titles&gt;
      &lt;Title languagecode=&quot;1033&quot;
             description=&quot;Translate&quot; /&gt;
    &lt;/Titles&gt;
    &lt;/LocLabel&gt;
    &lt;LocLabel Id=&quot;bing.incident.Bing.Button.BingTranslator.Description&quot;&gt;
    &lt;Titles&gt;
      &lt;Title languagecode=&quot;1033&quot;
             description=&quot;Translate text area with bing!&quot; /&gt;
    &lt;/Titles&gt;
    &lt;/LocLabel&gt;
  &lt;/LocLabels&gt;
&lt;/RibbonDiffXml&gt;
</pre>
<p>Here are the files to download if you want to use it:</p>
<ul>
<li>Option A
<ul>
<li>Complete unmanaged solution: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0.zip'>Translate_1_0.zip</a></li>
</ul>
</li>
<li>Option B
<ul>
<li>Unmanaged Image and JScript solution: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-ImageJS.zip'>Translate_1_0-ImageJS.zip</a>
<ul>
<li>You will need to edit the JScript to set your Bing API key.</li>
</ul>
</li>
<li>Managed Solution for the Ribbons on cases, letters, tasks, and emails: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-Ribbon-Managed.zip'>Translate_1_0-Ribbon-Managed.zip</a></li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/09/14/use-microsoft-translator-to-translate-text-in-crm-button-on-ribbon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CRM Attachment Image for CRM 2011 Entities</title>
		<link>http://mscrmblogger.com/2011/05/10/crm-attachment-image-for-crm-2011-entities/</link>
		<comments>http://mscrmblogger.com/2011/05/10/crm-attachment-image-for-crm-2011-entities/#comments</comments>
		<pubDate>Tue, 10 May 2011 15:34:35 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[CodePlex]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Microsoft Dynamics CRM 2011]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[Web Resource]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=440</guid>
		<description><![CDATA[<p>In a previous post I provided a screenshot with a contact photo on the form.  I have now released a version of the Silverlight control on codeplex at <a href="http://crmattachmentimage.codeplex.com">CRMAttachmentImage.CodePlex.com</a>.  It is a Silverlight control for adding images to any entity form in CRM 2011.</p>]]></description>
			<content:encoded><![CDATA[<p><i>The CRMAttachmentImage control downloads on codeplex have been updated to include gif and webcam support that I talk about in a <a href="http://mscrmblogger.com/2011/09/15/adding-imagetools-to-the-crm-attachment-image-for-crm-2011/">new article</a> that includes some instructions that may be helpful.</i></p>
<p>A while back Christian asked about this image control I had in a screenshot on one of my posts.  And while it was ok, it was far from being something I would throw into a production environment.  It was a starting point.  I am proud to say that I have put the Silverlight control on codeplex at <a href="http://crmattachmentimage.codeplex.com">CRMAttachmentImage.CodePlex.com</a>.  It is in beta because I am still working on putting the buttons on the ribbon instead of in the control.</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/03/ContactForm.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/03/ContactForm.png" alt="Contact Form - with Attachment Image Silverlight Control" title="Contact Form with CRM Attachment Image Silverlight Control" width="897" height="647" class="aligncenter size-full wp-image-365" /></a></p>
<p><i>** If anyone has any ideas for loading a file in JavaScript and sending it to the Silverlight control to load the data, I&#8217;m open to suggestions.</i></p>
<p>The image itself is stored as an attachment in the notes.  This way the control is utilizing CRM and not an external system to handle the images.  Simply put in order to use this your users will need to be able to read notes and create them.  They will also need the &quot;Customization &gt; ISV Extensions&quot; permission.  If you are not seeing the images, and everything else is right, then try checking the permissions.</p>
<p>Instructions are posted on the codeplex site, but it is fairly straight forward to add to a form.  First, you just upload the web-resource and create a text field to store the guid for the not (annotationid).  It <b>MUST BE ON THE FORM</b>, but it does not need to be visible, and you probably don&#8217;t want to make it searchable.  The web resource does require the id and type to be passed, and some additional parameters.</p>
<p>The parameters are separated by a pipe | instead of a comma.  An example parameter is:</p>
<pre>field=new_imageattachmentid|subject='Contact''s Image'|prefix='img-'</pre>
<p>Check out the full parameter list at <a href="http://crmattachmentimage.codeplex.com">CRMAttachmentImage.CodePlex.com</a>.  If you have any suggestions or comments, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/05/10/crm-attachment-image-for-crm-2011-entities/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>SilverCrmSoap: A Silverlight CRM Soap Library for CRM 2011</title>
		<link>http://mscrmblogger.com/2011/04/26/silvercrmsoap-a-silverlight-crm-soap-library-for-crm-2011/</link>
		<comments>http://mscrmblogger.com/2011/04/26/silvercrmsoap-a-silverlight-crm-soap-library-for-crm-2011/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 17:56:11 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[crm sdk]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Microsoft Dynamics CRM 2011]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=421</guid>
		<description><![CDATA[<p>SilverCrmSoap is a library built using the methods in <a href="http://msdn.microsoft.com/en-us/library/gg594452.aspx">Walkthrough: Use the SOAP Endpoint for Web Resources with Silverlight</a>. The SilverCrmSoap library simplifies SOAP Silverlight development for CRM 2011 by providing a class that does a lot of the heavy lifting right out of the box.</p>
<p>You can check out the SilverCrmSoap library on <a href="http://silvercrmsoap.codeplex.com/">CodePlex</a> or read more about it on the <a href="http://blogs.msdn.com/b/crm/archive/2011/04/26/silvercrmsoap-a-crm-soap-library-for-crm-2011.aspx">CRM Team Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>SilverCrmSoap is a library built using the methods in <a href="http://msdn.microsoft.com/en-us/library/gg594452.aspx">Walkthrough: Use the SOAP Endpoint for Web Resources with Silverlight</a>. The SilverCrmSoap library simplifies SOAP Silverlight development for CRM 2011 by providing a class that does a lot of the heavy lifting right out of the box.</p>
<p>In essence, the SilverCrmSoap library objectifies FetchXml allowing you to modify it easily in code, adds an XrmHelper for calling the context and page functions from a Silverlight application, a FormHelper for setting values on a form, and a SoapHelper for making all of your SOAP calls.  It becomes a real time saver because you don&#8217;t have to recompile it.  And, if your curious where/when to use it, it&#8217;s pretty straight forward.  If you need SOAP for CRM, then use the library and save time.</p>
<p>How do you know to use SOAP vs REST?</p>
<p><b>Use SOAP when&#8230;</b></p>
<ul>
<li>You need to use late binding to create a dynamic Silverlight application that works with any (or multiple) entities.</li>
<li>You need to execute a message.</li>
<li>You need to assign records.</li>
<li>You need to retrieve metadata.</li>
</ul>
<p>There are benefits to using the REST endpoint too, and being able to quickly leverage both end points in a project can be extremely helpful.</p>
<p><b>Use REST when&#8230;</b></p>
<ul>
<li>You need to early bind to objects.</li>
<li>You want to leverage LINQ with the early bound objects.</li>
<li>You want compile time type support and IntelliSense.</li>
</ul>
<p>You can check out the SilverCrmSoap library on <a href="http://silvercrmsoap.codeplex.com/">CodePlex</a> or read more about it on the <a href="http://blogs.msdn.com/b/crm/archive/2011/04/26/silvercrmsoap-a-crm-soap-library-for-crm-2011.aspx">CRM Team Blog</a>.</p>
<p>Enjoy!</p>
<p>-MSCRMBlogger</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/04/26/silvercrmsoap-a-silverlight-crm-soap-library-for-crm-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRM 2011: Toggle Visibility (Hide/Show) &#8211; Visibility.js</title>
		<link>http://mscrmblogger.com/2011/02/24/crm-2011-toggle-visibility/</link>
		<comments>http://mscrmblogger.com/2011/02/24/crm-2011-toggle-visibility/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 22:57:49 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[Microsoft Dynamics CRM 2011]]></category>
		<category><![CDATA[onchange]]></category>
		<category><![CDATA[onload event]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[toggle field]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=314</guid>
		<description><![CDATA[Visibility.js provides a simple way to set the visibility of navigation, section, tab, and form control elements using JScript.  It also allows you to change the visibility using the onClick event of a checkbox.]]></description>
			<content:encoded><![CDATA[<p>Often times we need to toggle the visiblity of an element based on the value of a field.  This JScript file adds the methods to accomplish this by calling the setVisibility function.  For example, in an onChange event for new_mypicklist I can call:</p>
<pre name="code" class="javascript">
setVisibility('section','new_mypicklist','section_main',42);
</pre>
<p>This hides the section_main section if the value is not 42, which simplifies the process of hiding and showing relevant information.</p>
<p>I also like to use checkboxes to handle the visibility of elements, but checkbox values dont&#8217; change until they lose focus.  To work around the issue, I register an onClick event during the form load instead of using the onChange event.  This unsupported method allows me to modify the value onClick and change the visibility immediately.  To use this I just need to call it in the onload:</p>
<pre name="code" class="javascript">
registerToggle('section', 'new_checkbox', 'section_main');
</pre>
<p>If you wanted to hide it when new_checkbox was false (or no), then you would need to specify the value, 0.</p>
<pre name="code" class="javascript">
registerToggle('section', 'new_checkbox', 'section_main',0);
</pre>
<p><b>JScript: visibility.js</b></p>
<p>This is the main javascript file&#8230; visibility.js that you would need to add and reference as a web resource in CRM 2011, everything except for the registerToggle uses supported methods.</p>
<pre name="code" class="javascript">
function registerToggle(t, attr, c, v) {
    if (typeof (v) === &quot;undefined&quot; || v === null) {
        var v = 1;
    }
    var ctrl = Xrm.Page.ui.controls.get(attr);
    var a = ctrl.getAttribute();
    var el = document.getElementById(attr);

    // Build Toggle Function
    var f = &quot;var ef=function() { &quot; +
              &quot;var a = Xrm.Page.data.entity.attributes.get(attr); &quot; +
              &quot;a.setValue(!a.getValue()); &quot; +
              &quot;setVisibility('&quot; + t + &quot;','&quot; + attr + &quot;','&quot; + c + &quot;',&quot; + v + &quot;);&quot; +
              &quot; };&quot;&#59;

    eval(f);

    // Attach to click event
    el.attachEvent('onclick', ef, false);

    // Set visibility
    setVisibility(t, attr, c, v);
}

function setVisibility(t, attr, c, v) {
    switch (t.toLowerCase().charAt(0)) {
        //tab
        case 't': setTabVisibility(attr, c, v);
            break;
        //section
        case 's': setSectionVisibility(attr, c, v);
            break;
        //control
        case 'c': setControlVisibility(attr, c, v);
            break;
        //navigation
        case 'n': setNavigationVisibility(attr, c, v);
            break;
    }
}

function setNavigationVisibility(attributename, navitemname, value) {
    var attribute = Xrm.Page.data.entity.attributes.get(attributename);
    var navitem = Xrm.Page.ui.navigation.items.get(navitemname);
    if (navitem === null)
    {
        return;
    }
    navitem.setVisible(attribute.getValue() == value);
}

function setTabVisibility(attributename, tabname, value) {
    var attribute = Xrm.Page.data.entity.attributes.get(attributename);
    var tab = Xrm.Page.ui.tabs.get(tabname);
    if (tab === null)
    {
        return;
    }
    tab.setVisible(attribute.getValue() == value);
}

function setSectionVisibility(attributename, sectionname, value) {
    var attribute = Xrm.Page.data.entity.attributes.get(attributename);
    var tabs = Xrm.Page.ui.tabs.get();
    for(var i in tabs) {
        var tab = tabs[i];
        var section = tab.sections.get(sectionname);
        if (section !== null) {
            section.setVisible(attribute.getValue() == value);
            return;
        }
    }
}

function setControlVisibility(attributename, controlname, value) {
    var attribute = Xrm.Page.data.entity.attributes.get(attributename);
    var control = Xrm.Page.ui.controls.get(controlname);
    if (control === null)
    {
        return;
    }
    control.setVisible(attribute.getValue() == value);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/02/24/crm-2011-toggle-visibility/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Set a default email template for new emails on cases.</title>
		<link>http://mscrmblogger.com/2009/10/02/set-a-default-email-template-for-new-emails-on-cases/</link>
		<comments>http://mscrmblogger.com/2009/10/02/set-a-default-email-template-for-new-emails-on-cases/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 22:31:58 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 4]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics CRM 4]]></category>
		<category><![CDATA[onload event]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=152</guid>
		<description><![CDATA[<p>In response to <a href="http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/2d2c28ba-891d-4ebc-9c54-92c7cc21a034">Peter Bergman's post on the CRM forums</a>, I traversed Microsoft's code.  I determined that the ApplyTemplate loads a specific page, and on that page, the ok button sets the information on the calling page.  I melded the ApplyTemplate and ok methods together to create LoadTemplate provided below.  With the right parameters, it will set the default template.</p>]]></description>
			<content:encoded><![CDATA[<p>In response to <a href="http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/2d2c28ba-891d-4ebc-9c54-92c7cc21a034">Peter Bergman&#8217;s post on the CRM forums</a>, I traversed Microsoft&#8217;s code.  I determined that the ApplyTemplate loads a specific page, and on that page, the ok button sets the information on the calling page.  I melded the ApplyTemplate and ok methods together to create LoadTemplate provided below.  With the right parameters, it will set the default template.</p>
<pre name="code" class="javascript">
function LoadTemplate(templateid, objectid, objecttypecode)
{
    var command = new RemoteCommand("EmailTemplateService", "GetInstantiatedEmailTemplate");
    command.SetParameter("templateId", templateid );
    command.SetParameter("objectId", objectid);
    command.SetParameter("objectTypeCode", objecttypecode);

    var result = command.Execute();

    if (result.Success)
    {
        var o = new Object();
        o.EmailBody = "";
        o.EmailSubject = "";
        if(typeof(result.ReturnValue) == "string")
        {
            oXml = CreateXmlDocument(false);
            oXml.loadXML(result.ReturnValue);
            o.EmailBody = oXml.selectSingleNode("template/body").text;
            o.EmailSubject = oXml.selectSingleNode("template/subject").text;

            crmForm.all.description.InsertValue( o.EmailBody  );
            if( !IsNull( o.EmailSubject ) &#038;&#038; o.EmailSubject.length > 0 )
            {
                crmForm.all.subject.DataValue =
                    CrmEncodeDecode.CrmHtmlDecode(o.EmailSubject).substr(0, crmForm.all.subject.MaxLength);
            }
        }
    }
}
</pre>
<p>To set the default template, you need the templateid, you can get this by opening the template and hitting CTRL-N, or you can just operate in tab mode and see all the id&#8217;s and urls at all times. I prefer that view&#8230;  The below code uses the templateid to set a default email template when a new email is created from a case, account, and contact.  You could easily extend this for other templates and entities.  Currently I am setting them all to the same template, which won&#8217;t work.</p>
<pre name="code" class="javascript">
var CRM_FORM_TYPE_CREATE = 1;
if (crmForm.FormType==CRM_FORM_TYPE_CREATE)
{
    var otype = 0;
    var tmpid = '';
    switch (crmForm.all.regardingobjectid.DataValue[0].typename)
    {
        case 'incident': otype=112; tmpid='{F8E179BF-8E7C-DA11-BF9A-00142216345E}'; break;
        case 'account':  otype=1;   tmpid='{F8E179BF-8E7C-DA11-BF9A-00142216345E}'; break;
	case 'contact':  otype=2;   tmpid='{F8E179BF-8E7C-DA11-BF9A-00142216345E}'; break;
        default: return;
    }

    var oid = crmForm.all.regardingobjectid.DataValue[0].id;

    if (tmpid==undefined || tmpid==null) return;

    LoadTemplate(tmpid, oid, otype);
}
</pre>
<p>This could be extended using my <a href="http://mscrmblogger.com/2009/09/30/get-current-users-business-unit-for-hiding-fields/">business unit</a> lookup or getting roles assigned to a user..</p>
<p>Let me know if you have any questions &#8211; or if you figure out a way to get the id of a template from the name of one&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2009/10/02/set-a-default-email-template-for-new-emails-on-cases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRM4: Hide Fields or Tabs by Role with Javascript</title>
		<link>http://mscrmblogger.com/2009/09/30/hide-fields-or-tabs-by-role-with-javascript/</link>
		<comments>http://mscrmblogger.com/2009/09/30/hide-fields-or-tabs-by-role-with-javascript/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 13:13:32 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics CRM 4]]></category>
		<category><![CDATA[onload event]]></category>
		<category><![CDATA[roles]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=131</guid>
		<description><![CDATA[Do you need to hide fields or tabs based on security roles.  Here is an easy way to add the functionality to your CRM, use my code example.]]></description>
			<content:encoded><![CDATA[<p>Here are a set of methods to assist in hiding tabs or sections based on role, it is a modified version of <a href="http://jianwang.blogspot.com/2008/01/crm-40-check-current-users-security.html" target="_blank">Jimmy Wang&#8217;s version</a>.</p>
<p>First, we need a set of functions to facilitate our our process.  We need to get the roles of the current user, <b><i>GetCurrentUserRoles</i></b>.  Then we need to see if the user has the role, <b><i>UserHasRole</i></b>.  Finally we can hide the fields (<b><i>HideFieldByRole</i></b>) or tabs (<b><i>HideTabByRole</i></b>).</p>
<p>
<b>GetCurrentUserRoles</b><br />
The first thing we need to do is get a list of roles according to the current user.  There are a couple of different ways to do this.  You could use the RemoteCommand to get the current user and then their roles, a blog post by <a href="http://www.crowehorwath.com/cs/blogs/crm/archive/2008/05/08/hide-show-fields-in-crm-4-0-based-on-security-role.aspx" target="_blank">Zahara Hirani on Hide Show Fields in CRM 4 based on security role</a> outlines this.  However, I do not want to make multiple request for the same information.  I want to get the roles for the current user in one line.  Below shows the GetCurrentUserRoles that implements a RetrieveMultiple query to get the names of the roles that a user has in one request.</p>
<pre name="code" class="javascript">
function GetCurrentUserRoles()
{
  var xml = &quot;&quot; +
    &quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?&gt;&quot; +
    &quot;&lt;soap:Envelope xmlns:soap=\&quot;&quot; +
    &quot;http://schemas.xmlsoap.org/soap/envelope/&quot; +
    &quot;\&quot; xmlns:xsi=\&quot;http://www.w3.org/2001/XMLSchema-instance\&quot;&quot; +
    &quot; xmlns:xsd=\&quot;http://www.w3.org/2001/XMLSchema\&quot;&gt;&quot; +
    GenerateAuthenticationHeader() +
    &quot; &lt;soap:Body&gt;&quot; +
    &quot; &lt;RetrieveMultiple xmlns=\&quot;&quot; +
    &quot;http://schemas.microsoft.com/crm/2007/WebServices\&quot;&gt;&quot; +
    &quot; &lt;query xmlns:q1=\&quot;&quot; +
    &quot;http://schemas.microsoft.com/crm/2006/Query&quot; +
    &quot;\&quot; xsi:type=\&quot;q1:QueryExpression\&quot;&gt;&quot; +
    &quot; &lt;q1:EntityName&gt;role&lt;/q1:EntityName&gt;&quot; +
    &quot; &lt;q1:ColumnSet xsi:type=\&quot;q1:ColumnSet\&quot;&gt;&quot; +
    &quot; &lt;q1:Attributes&gt;&quot; +
    &quot; &lt;q1:Attribute&gt;name&lt;/q1:Attribute&gt;&quot; +
    &quot; &lt;/q1:Attributes&gt;&quot; +
    &quot; &lt;/q1:ColumnSet&gt;&quot; +
    &quot; &lt;q1:Distinct&gt;false&lt;/q1:Distinct&gt;&quot; +
    &quot; &lt;q1:LinkEntities&gt;&quot; +
    &quot; &lt;q1:LinkEntity&gt;&quot; +
    &quot; &lt;q1:LinkFromAttributeName&gt;roleid&lt;/q1:LinkFromAttributeName&gt;&quot; +
    &quot; &lt;q1:LinkFromEntityName&gt;role&lt;/q1:LinkFromEntityName&gt;&quot; +
    &quot; &lt;q1:LinkToEntityName&gt;systemuserroles&lt;/q1:LinkToEntityName&gt;&quot; +
    &quot; &lt;q1:LinkToAttributeName&gt;roleid&lt;/q1:LinkToAttributeName&gt;&quot; +
    &quot; &lt;q1:JoinOperator&gt;Inner&lt;/q1:JoinOperator&gt;&quot; +
    &quot; &lt;q1:LinkEntities&gt;&quot; +
    &quot; &lt;q1:LinkEntity&gt;&quot; +
    &quot; &lt;q1:LinkFromAttributeName&gt;systemuserid&lt;/q1:LinkFromAttributeName&gt;&quot; +
    &quot; &lt;q1:LinkFromEntityName&gt;systemuserroles&lt;/q1:LinkFromEntityName&gt;&quot; +
    &quot; &lt;q1:LinkToEntityName&gt;systemuser&lt;/q1:LinkToEntityName&gt;&quot; +
    &quot; &lt;q1:LinkToAttributeName&gt;systemuserid&lt;/q1:LinkToAttributeName&gt;&quot; +
    &quot; &lt;q1:JoinOperator&gt;Inner&lt;/q1:JoinOperator&gt;&quot; +
    &quot; &lt;q1:LinkCriteria&gt;&quot; +
    &quot; &lt;q1:FilterOperator&gt;And&lt;/q1:FilterOperator&gt;&quot; +
    &quot; &lt;q1:Conditions&gt;&quot; +
    &quot; &lt;q1:Condition&gt;&quot; +
    &quot; &lt;q1:AttributeName&gt;systemuserid&lt;/q1:AttributeName&gt;&quot; +
    &quot; &lt;q1:Operator&gt;EqualUserId&lt;/q1:Operator&gt;&quot; +
    &quot; &lt;/q1:Condition&gt;&quot; +
    &quot; &lt;/q1:Conditions&gt;&quot; +
    &quot; &lt;/q1:LinkCriteria&gt;&quot; +
    &quot; &lt;/q1:LinkEntity&gt;&quot; +
    &quot; &lt;/q1:LinkEntities&gt;&quot; +
    &quot; &lt;/q1:LinkEntity&gt;&quot; +
    &quot; &lt;/q1:LinkEntities&gt;&quot; +
    &quot; &lt;/query&gt;&quot; +
    &quot; &lt;/RetrieveMultiple&gt;&quot; +
    &quot; &lt;/soap:Body&gt;&quot; +
    &quot;&lt;/soap:Envelope&gt;&quot; +
    &quot;&quot;;  

  var xmlHttpRequest = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);  

  xmlHttpRequest.Open(&quot;POST&quot;, &quot;/mscrmservices/2007/CrmService.asmx&quot;, false);
  xmlHttpRequest.setRequestHeader(&quot;SOAPAction&quot;,
    &quot; http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple&quot;);
  xmlHttpRequest.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml; charset=utf-8&quot;);
  xmlHttpRequest.setRequestHeader(&quot;Content-Length&quot;, xml.length);
  xmlHttpRequest.send(xml);  

  var resultXml = xmlHttpRequest.responseXML;
  return(resultXml);
}
</pre>
<p>The next method is a simple method for searching the XML result from GetCurrentUserRoles.  By passing it the roles you are looking for and the roles the user has, it will determine if there is a match.  The roles it is passed is separated by a pipe (|).</p>
<pre name="code" class="javascript">
function UserHasRole(roleNames, rolesXML)
{
  // split roleNames on pipe
  var matchon = roleNames.split('|');

  if(rolesXML != null)
  {
    //select the node text
    var roles = rolesXML.selectNodes("//BusinessEntity/q1:name");
    if(roles != null)
    {
      for( i = 0; i < roles.length; i++)
      {
        for (j = 0; j < matchon.length; j++)
	{
	  // If there is a match, return true, found
	  if (roles[i].text == matchon[j]) return true;
        }
      }
    }
  }
  //otherwise return false
  return false;
}
</pre>
<p>Finally, we can now implement helper methods to allow the hiding of a tab or a field if a user DOES NOT have a specific role.</p>
</pre>
<pre name="code" class="javascript">
function HideTabByRole(role, roles, tabnumber)
// Tab number starts on 0
{
  var tab = document.getElementById('tab'+tabnumber+'Tab');
  var usrRole = UserHasRole(role, roles);
  if(!usrRole)
  {
    tab.style.display = "none";
  }
}

function HideFieldByRole(role, roles, field,cfield,dfield)
{
  var usrRole = UserHasRole(role, roles);
  if(!usrRole)
  {
    field.style.visibility = 'hidden';
    field.style.position = 'absolute';
    cfield.style.visibility = 'hidden';
    cfield.style.position = 'absolute';
    dfield.visibility = 'hidden';
    dfield.style.position = 'absolute';
  }
}
</pre>
<p>To implement this process, all you have to do is put every piece of code in this article inside your onload with the following customized for your situation.</p>
<pre name="code" class="javascript">
var UserRoles = GetCurrentUserRoles();

HideTabByRole('Account Managers|SystemAdministrators', UserRoles, 3);

HideFieldByRole('Account Managers', UserRoles,
                crmForm.all.parentcustomerid,
                crmForm.all.parentcustomerid_c,
                crmForm.all.parentcustomerid_d);
</pre>
<p>If you have any questions of problems implementing this in your environment, please let me know, and I&#8217;ll do my best to help you get it working</p>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2009/09/30/hide-fields-or-tabs-by-role-with-javascript/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

