Tags

CRM & Technology Management


Sales and Marketing Advisor


Sign Up For the Newsletter

Login

Welcome to the Technology Advisors Blog!!

Technology Advisors CRM and Technical Information
Apr 13
2011

Adding a Multi-Select Picklist to Microsoft Dynamics CRM 2011

Posted by: Administrator in MyBlog

Administrator

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-multi-select-picklist.aspx)
 but needed customization to work for MCRM 2011

Changes to original code:
    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.

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

Microsoft Dynamics CRM

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.
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:
     Go to  "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"

Microsoft Dynamics CRM

4.  Add the event to the form:
    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
5.  Save and Publish All Customizations


Here is the Sample code - You'll need to change the values in RED

 

function AccountOnLoad ()

{

// PL - the picklist attribute; PLV - used to save selected picklist values     

var PL = crmForm.all.new_areaaccess;     //CREATE NEW PICKLIST

var PLV = crmForm.all.new_areaaccesstext;  //CREATE NEW TEXT FIELD TO STORE STRING

 

PL.style.display = "none";       //HIDES THE CONTROL

PLV.style.display = "none";     //HIDES THE CONTROL

 

    // Create a DIV container    

    var addDiv = document.createElement("<div style='overflow-y:auto; height:80px; border:1px #6699cc solid; background-color:#ffffff;' />");    

    PL.parentNode.appendChild(addDiv);    

    // Initialise checkbox controls    

 

    for( var i = 1; i < PL.options.length; i++ )    

    {    

        var pOption = PL.options[i];    

        if( !IsChecked( pOption.text ) )   

        var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' style='border:none; width:25px; align:left;' />" );

        else    

        var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' checked='checked' style='border:none; width:25px; align:left;' />" );

        var addLabel = document.createElement( "<label />");    

        addLabel.innerText = pOption.text;    

 

        var addBr = document.createElement( "<br>"); //it's a 'br' flag    

 

        PL.nextSibling.appendChild(addInput);    

        PL.nextSibling.appendChild(addLabel);    

        PL.nextSibling.appendChild(addBr);

    }

 

   // Check if it is selected    

   function IsChecked( pText )

   {

   if(PLV.value != "")

      {

      var PLVT = PLV.value.split("||");

      for( var i = 0; i < PLVT.length; i++ )

      {

         if( PLVT[i] == pText )

         return true;

      }

    }

    return false;

   }

}

 

function CallOnChangeEvent()

{

      var PL = crmForm.all.new_areaaccess;  

      var PLV = crmForm.all.new_areaaccesstext;

      PLV.value = "";

      var getInput = PL.nextSibling.getElementsByTagName("input");

      for( var i = 0; i < getInput.length; i++ )

      {

         if( getInput[i].checked)

         {

            PLV.value += getInput[i].nextSibling.innerText + "||";

         }

      }

 

     //MUST DO THIS TO TRIGGER A SAVE EVENT

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

    Name.setValue(PLV.value);

}

Hits: 2803
Comments (1)Add Comment
0
...
written by James Smith, January 20, 2012
Per the posted code to sum the sub-grid values, I keep running into the problem that getCellValue returns a string that appears to be a valid candidate for parseFloat (i.e. is comes out as say $40,000.00, and debugging line alert(cellValue.replace(/[$,]+/g,"")); shows 40000.00, but after the parseFloat line typeof(cellValue) returns number and alert(cellValue) returns NaN. Naturally, the value assignment fails with a message that it needs a numeric value in the proper range. Has anyone else encountered this issue or come up with a workaround? We are using CRM 2011 5.0.9688.1544. I am wondering if a version rollup broke this?

Write comment
smaller | bigger

security code
Write the displayed characters


busy