Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Contact Me
  • Welcome

A multi-select picklist for MS CRM

Nicolas Galler | August 22, 2008

One of the difference between the MSCRM and the Saleslogix editors is the richness of the controls included with Saleslogix.  For example, the picklist available by default with MSCRM does not support multiple selection.  Fortunately it is easy to remedy using a little bit of Javascript in the form.

The key requisites were:

  • should be able to manage the values for the picklist using the same interface as regular picklists
  • should not have to customize the code (just paste the base code and add one line to initialize the picklist)
  • does not disrupt tab navigation (I did not 100% succeed on that one because you can only tab forward, not backward)

image

To make it work I simply created 2 attributes: "HobbiesList" points to the picklist, and "Hobbies" saves the actual values (this wastes a field in the contact table but we only lose 4 bytes).  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.

image

This is the javascript I used in the "Load" event on the form.  This part is generic and does not have to be customized – I just paste it at the beginning of the code.  I struggled a bit to get the positioning right, the rest is pretty classic stuff:

// make the textbox act as a multi select picklist including the elements of the 
// given select control
function makeMultiSelectPicklist(txt, pkl){
    txt.associatedPicklist = pkl;
    pkl.associatedTextbox = txt;
    txt.readonly = true;

    // hide containing row
    for(var p = pkl; p ; p = p.parentNode){
    if(p.tagName == "TR"){
        // hide the entire row (the picklist will be moved out)
        p.style.display = "none";
        break;
    }
    }

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

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

    var s = [];
    for(var i=0; i < pkl.options.length; i++){
        if(pkl.options[i].text && pkl.options[i].selected){
        s.push(pkl.options[i].text);
        }
    }
    txt.value = s.join("; ");
    pkl.style.display = "none";
    }

    // break reference to avoid leak on IE6
    txt = null;
    pkl = null;
}

And finally I add this line at the end of the Load event to initialize the picklist:

makeMultiSelectPicklist(document.all.new_hobbies, document.all.new_hobbieslist);

A little bit more work than in Saleslogix but not too terrible!  And, it works somewhat better for tab navigation.  One thing worth noting – 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.

Categories
MSCRM
Tags
Javascript, MSCRM
Comments rss
Comments rss
Trackback
Trackback

« Automatic Assembly Version Number 1st Saleslogix .NET Extension »

One Response to “A multi-select picklist for MS CRM”

  1. Rama says:
    August 25, 2008 at 3:37 pm

    Thanks, been looking for that one

Leave a Reply

Click here to cancel reply.

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (24)

Post History

  • 2010
    • January (3)
    • March (1)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox