<?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>Nico&#039;s CRM &#187; MSCRM</title>
	<atom:link href="http://blog.nicocrm.com/category/mscrm/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nicocrm.com</link>
	<description>Programming, technology, and CRM - from a Belgian programmer exiled to Missouri</description>
	<lastBuildDate>Thu, 28 Jul 2011 22:02:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>A multi-select picklist for MS CRM</title>
		<link>http://blog.nicocrm.com/2008/08/22/a-multi-select-picklist-for-ms-crm/</link>
		<comments>http://blog.nicocrm.com/2008/08/22/a-multi-select-picklist-for-ms-crm/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 04:34:12 +0000</pubDate>
		<dc:creator>Nicolas Galler</dc:creator>
				<category><![CDATA[MSCRM]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.chivinou.net/2008/08/22/a-multi-select-picklist-for-ms-crm/</guid>
		<description><![CDATA[One of the difference between the MSCRM and the Saleslogix editors is the richness of the controls included with Saleslogix.&#160; For example, the picklist available by default with MSCRM does not support multiple selection.&#160; Fortunately it is easy to remedy using a little bit of Javascript in the form. The key requisites were: should be [...]]]></description>
			<content:encoded><![CDATA[<p>One of the difference between the MSCRM and the Saleslogix editors is the richness of the controls included with Saleslogix.&#160; For example, the picklist available by default with MSCRM does not support multiple selection.&#160; Fortunately it is easy to remedy using a little bit of Javascript in the form.</p>
<p>The key requisites were:</p>
<ul>
<li>should be able to manage the values for the picklist using the same interface as regular picklists</li>
<li>should not have to customize the code (just paste the base code and add one line to initialize the picklist)</li>
<li>does not disrupt tab navigation (I did not 100% succeed on that one because you can only tab forward, not backward)</li>
</ul>
<p><a href="/wp-content/uploads/2008/08/image1.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="108" alt="image" src="/wp-content/uploads/2008/08/image-thumb1.png" width="548" border="0" /></a> </p>
<p>To make it work I simply created 2 attributes: &quot;HobbiesList&quot; points to the picklist, and &quot;Hobbies&quot; saves the actual values (this wastes a field in the contact table but we only lose 4 bytes).&#160; Both attributes are present on the form but at runtime the HobbiesList is hidden and converted to a multiple selection list to be displayed only when you tab into the Hobbies textbox.</p>
<p><a href="/wp-content/uploads/2008/08/image2.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="198" alt="image" src="/wp-content/uploads/2008/08/image-thumb2.png" width="487" border="0" /></a> </p>
<p>This is the javascript I used in the &quot;Load&quot; event on the form.&#160; This part is generic and does not have to be customized &#8211; I just paste it at the beginning of the code.&#160; I struggled a bit to get the positioning right, the rest is pretty classic stuff:</p>
<pre class="csharpcode"><span class="rem">// make the textbox act as a multi select picklist including the elements of the </span>
<span class="rem">// given select control</span>
<span class="kwrd">function</span> makeMultiSelectPicklist(txt, pkl){
    txt.associatedPicklist = pkl;
    pkl.associatedTextbox = txt;
    txt.<span class="kwrd">readonly</span> = <span class="kwrd">true</span>;

    <span class="rem">// hide containing row</span>
    <span class="kwrd">for</span>(<span class="kwrd">var</span> p = pkl; p ; p = p.parentNode){
    <span class="kwrd">if</span>(p.tagName == <span class="str">&quot;TR&quot;</span>){
        <span class="rem">// hide the entire row (the picklist will be moved out)</span>
        p.style.display = <span class="str">&quot;none&quot;</span>;
        <span class="kwrd">break</span>;
    }
    }

    <span class="rem">// setup position for the multi select picklist</span>
    <span class="kwrd">var</span> container = document.createElement(<span class="str">&quot;span&quot;</span>);
    container.style.position = <span class="str">&quot;relative&quot;</span>;
    container.style.top = <span class="str">&quot;0px&quot;</span>;
    container.style.left = <span class="str">&quot;0px&quot;</span>;
    container.style.width = <span class="str">&quot;0px&quot;</span>;
    container.style.height = <span class="str">&quot;0px&quot;</span>;
    txt.parentNode.insertBefore(container, txt);
    container.insertBefore(pkl, <span class="kwrd">null</span>);
    pkl.style.display = <span class="str">&quot;none&quot;</span>;
    pkl.style.position = <span class="str">&quot;absolute&quot;</span>;
    pkl.style.top = <span class="str">&quot;0px&quot;</span>;
    pkl.style.left = <span class="str">&quot;0px&quot;</span>;
    pkl.multiple = <span class="str">&quot;true&quot;</span>;

    txt.onfocus = <span class="kwrd">function</span>(e) {
    <span class="kwrd">var</span> txt = <span class="kwrd">this</span>;
    <span class="kwrd">var</span> pkl = txt.associatedPicklist;
    <span class="kwrd">var</span> values = <span class="str">&quot;|&quot;</span> + txt.value.replace(/; /g, <span class="str">&quot;|&quot;</span>) + <span class="str">&quot;|&quot;</span>;
    pkl.style.display = <span class="str">&quot;block&quot;</span>;
    pkl.style.width = txt.offsetWidth + <span class="str">&quot;px&quot;</span>;
    <span class="kwrd">for</span>(<span class="kwrd">var</span> i=0; i &lt; pkl.options.length; i++){
        pkl.options[i].selected = <span class="kwrd">new</span> RegExp(<span class="str">&quot;\\|&quot;</span> + pkl.options[i].text + <span class="str">&quot;\\|&quot;</span>).test(values);
    }
    pkl.focus();
    }
    pkl.onblur = <span class="kwrd">function</span>(e) {
    <span class="kwrd">var</span> pkl = <span class="kwrd">this</span>;
    <span class="kwrd">var</span> txt = pkl.associatedTextbox;

    <span class="kwrd">var</span> s = [];
    <span class="kwrd">for</span>(<span class="kwrd">var</span> i=0; i &lt; pkl.options.length; i++){
        <span class="kwrd">if</span>(pkl.options[i].text &amp;&amp; pkl.options[i].selected){
        s.push(pkl.options[i].text);
        }
    }
    txt.value = s.join(<span class="str">&quot;; &quot;</span>);
    pkl.style.display = <span class="str">&quot;none&quot;</span>;
    }

    <span class="rem">// break reference to avoid leak on IE6</span>
    txt = <span class="kwrd">null</span>;
    pkl = <span class="kwrd">null</span>;
}</pre>
<p>And finally I add this line at the end of the Load event to initialize the picklist:</p>
<pre class="csharpcode">makeMultiSelectPicklist(document.all.new_hobbies, document.all.new_hobbieslist);</pre>
<p>A little bit more work than in Saleslogix but not too terrible!&#160; And, it works somewhat better for tab navigation.&#160; One thing worth noting &#8211; the Javascript editor on the CRM designer is so terrible, it is a lot easier to do the development in a separate file then paste it in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicocrm.com/2008/08/22/a-multi-select-picklist-for-ms-crm/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

