Microsoft Dynamics CRM 2011 doesn't have multi-select picklist controls available. The standard CRM picklist can only save one value in the database and it is not easy to extend this functionality. In addition, you have to deal with the Advanced Find Feature.

Original code came from Jim Wang (http://blogs.msdn.com/b/crm/archive/2009/03/31/crm-4-0-checkbox-style-mu...) but needed customization to work for MCRM 2011

Changes to original code:

var Name = Xrm.Page.data.entity.attributes.get("new_areaaccesstext");

Name.setValue(PLV.value);

  1. I added an "onClick()" event to build the string of values each time a checkbox is checked.
  2. The original code did not save it's values into the database when the "Save" button was clicked, so I added 2 additional lines of code to Set the values in the textbox and allow MCRM to save the data.
Microsoft Dynamics CRM Multi-Select Picklist

The script below will draw a checkbox style multi-select picklist control on the CRM form, and then get options from the real picklist attribute.

"Settings", "Customization", "Customize the System". Click "Web Resource" and then "New"

Type in the name of the Web Resource, Display Name...

Select "Script (JScript)" and choose the Language.

Click the Text Editor button and paste the code below to the source area on the form.

Click "OK" then "Save and Close"

Screenshot of the text editor in Microsoft Dynamics CRM

Go to "Settings", "Customization", "Customize the System". Expand "Entity" then expand "Account" and click "Forms"

Select the form where you added the picklist and textbox. And click "Form Properties" button

Add the new Web Resource to the Library by clicking the "Add" button, then select the new web Resource and click "OK"

In the Event Handlers section click "Add", select the Library file and enter the Function name (In our example: "AccountOnLoad") and click "OK" and "OK" again

  1. Controls - Create a picklist and populate it with values & a textbox to store the string of values selected from the picklist
  2. Put the picklist on the form where you want the new Multi Select Picklist to show up
  3. Create a web Resource:
  4. Add the event to the form:
  5. Save and Publish All Customizations

Here is the Sample code - You'll need to change the values new_areaaccess and new_areaaccesstext on lines 4, 5, 50, 51, and 63.

  1. function AccountOnLoad ()
  2. {
  3. // PL - the picklist attribute; PLV - used to save selected picklist values
  4. var PL = crmForm.all.new_areaaccess; //CREATE NEW PICKLIST
  5. var PLV = crmForm.all.new_areaaccesstext; //CREATE NEW TEXT FIELD TO STORE STRING
  6.  
  7. PL.style.display = "none"; //HIDES THE CONTROL
  8. PLV.style.display = "none"; //HIDES THE CONTROL
  9.  
  10. // Create a DIV container
  11. var addDiv = document.createElement("<div style='overflow-y:auto; height:80px; border:1px #6699cc solid; background-color:#ffffff;' />");
  12. PL.parentNode.appendChild(addDiv);
  13. // Initialise checkbox controls
  14.  
  15. for( var i = 1; i < PL.options.length; i++ )
  16. {
  17. var pOption = PL.options[i];
  18. if( !IsChecked( pOption.text ) )
  19. var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' style='border:none; width:25px; align:left;' />" );
  20. else
  21. var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' checked='checked' style='border:none; width:25px; align:left;' />" );
  22. var addLabel = document.createElement( "<label />");
  23. addLabel.innerText = pOption.text;
  24.  
  25. var addBr = document.createElement( "<br>"); //it's a 'br' flag
  26.  
  27. PL.nextSibling.appendChild(addInput);
  28. PL.nextSibling.appendChild(addLabel);
  29. PL.nextSibling.appendChild(addBr);
  30. }
  31.  
  32. // Check if it is selected
  33. function IsChecked( pText )
  34. {
  35. if(PLV.value != "")
  36. {
  37. var PLVT = PLV.value.split("||");
  38. for( var i = 0; i < PLVT.length; i++ )
  39. {
  40. if( PLVT[i] == pText )
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. }
  47.  
  48. function CallOnChangeEvent()
  49. {
  50. var PL = crmForm.all.new_areaaccess;
  51. var PLV = crmForm.all.new_areaaccesstext;
  52. PLV.value = "";
  53. var getInput = PL.nextSibling.getElementsByTagName("input");
  54. for( var i = 0; i < getInput.length; i++ )
  55. {
  56. if( getInput[i].checked)
  57. {
  58. PLV.value += getInput[i].nextSibling.innerText + "||";
  59. }
  60. }
  61.  
  62. //MUST DO THIS TO TRIGGER A SAVE EVENT
  63. var Name = Xrm.Page.data.entity.attributes.get("new_areaaccesstext");
  64. Name.setValue(PLV.value);
  65. }
Posted in:

Start a Project With Us

Submit your email below to get in touch with our team.