CRM – Removing a Picklist Value

In CRM, I have a field that allows the user to select from a set of Picklist values.  One of the values is no longer active.  I did not want to delete the Picklist value and lose historical data, but I did not want users to be able to select that value for new Opportunities.  This functionality is very easy to apply on the client-side of the CRM form.

In the following example, the “Form_onload” function is wired up to the CRM form onload event.

function Form_onload() {  
     HandleBusinessUnitValues();
}

function
HandleBusinesUnitValues() {
  
try {
      // Check to see if the value we want to remove is the value that is currently selected.
      // We will only remove the value from the picklist if it is not selected.

      var wdc = ‘8’;
      var currentValue = Xrm.Page.getAttribute(“crm_picklist_field_name”).getValue();
      currentValue
= currentValue == null ? : currentValue ;
     
if (currentValue != wdc) {
         
var pickListField = Xrm.Page.getControl(“crm_picklist_field_name”);
          pickListField.removeOption(wdc);
      }
   }
   catch (Exception) { }
}

 

 

 

 

Leave a Reply