Thursday, July 7, 2011

Multiselect option set in CRM 2011

Multiselect option set in CRM 2011


Please refer below Code for implementation
new_subject :  is option set type field
 new_subject_value: is Text field which holds the selected values
 
new_subject  and new_subject_value will be hidden by JavaScript.
onload () we will call   “function Onload_Entity()”
and  onSave() we will call “ function OnSave_Entity()”.
//--------------------------------------------Code ---------------------------------------------------------------------//
var var_new_picklistacc = 'new_subject';
var var_new_picklistvalueacc = 'new_subjectvalue';

//Method to convert picklist to multi select picklist OnLoad of entity
function Onload_Entity()
{
var PL = document.all.new_subject;
var PLV = document.all.new_subjectvalue;
Xrm.Page.getControl('new_subjectvalue').setVisible(false);
ConvertToMultiSelectext(PL,PLV,"80");
}

// Save the selected text, this field can also be used in Advanced Find
function OnSave_Entity()
{
    //Update >> Provide picklist schema name
    var PL = document.all.new_subject;  OnSaveext(PL,var_new_picklistvalueacc);
}

///////Supported functions
function ConvertToMultiSelectext(p_PL,p_PLV,ht)
{
  // Create a DIV container
  var addDiv = document.createElement("<div style='overflow-y:auto; height:"+ht+"px; border:1px #6699cc solid; background-color:#ffffff;'
/>");
  p_PL.parentNode.appendChild(addDiv);





 // Initialise checkbox controls
  for( var i = 0; i < p_PL.,"length; i++ )
  {
    var pOption = p_PL.options[i];
    if(pOption.text!="") {
    if( !IsChecked( pOption.text , p_PL, p_PLV)  )
      var addInput = document.createElement("<input type='checkbox' style='border:none; width:25px; align:left;' />" );
    else
    var addInput = document.createElement("<input type='checkbox' 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

    p_PL.nextSibling.appendChild(addInput);
    p_PL.nextSibling.appendChild(addLabel);
    p_PL.nextSibling.appendChild(addBr);
       }
  }
}
  // Check if it is selected
  function IsChecked( pText , PL, PLV)
  {
     var PLV1 = PLV.innerText;
    if(PLV1 != "")
    {
      var PLVT = PLV1.split(";");
      for( var i = 0; i < PLVT.length; i++ )
      {
        if( PLVT[i] == pText )
          return true;
      }
    }
        return false;
  }

function OnSaveep_var_new_picklistvaluext()
{
    var PL = document.all.new_subject;
    var getInput = PL.nextSibling.getElementsByTagName("input");
    var result = '';
    for( var i = 0; i < getInput.length; i++ )
    {
      if( getInput[i].checked)
      {
        result += getInput[i].nextSibling.innerText + ";";
      }
    }

    //save value
    control = Xrm.Page.getControl(var_new_picklistvalueacc);
    attribute = control.getAttribute();
    attribute.setValue(result);
}

No comments:

Post a Comment

Power Automate Optimization: Filter Rows vs Trigger Conditions - When and Why to Use Each

Filter Rows vs Trigger Conditions in Power Automate Filter Rows vs Trigger Conditions in Power Automate Why your flow...