DenLun DenLun - 1 year ago 118
Javascript Question

Filter a child picklist in CRM 2011

I'm trying to convert javascript code from CRM 4.0 to CRM 2011.
I'm having problems with a picklist filter.

My function is on the onchange of the parent picklist. It works the first time but the second it erase everything from my child picklist.

This is the part where I suppose to reset the picklist

oSubPicklist.originalPicklistValues = oSubPicklist.getOptions();
oSubPicklist.getOptions = oSubPicklist.originalPicklistValues;
oSubPicklist.setOptions = oSubPicklist.originalPicklistValues;

And this is the part where i remove all the option not related:
oTempArray is an array with the options that i want to keep. If a check the "oSubPicklist.getOptions.length" the value is the same that my original picklist.

for (var i=oSubPicklist.getOptions.length; i >= 0;i--)
if(oTempArray[i] != true)


Edit: I solved declaring a global var with the originalPickList in the onLoad event and:

for (var i=0; i< oSubPicklist.originalPicklistValues.length; i++)
for (var j=0; j< oDesiredOptions.length; j++)
if (i == oDesiredOptions[j])

Answer Source

Your code is not very clear to me: May be you could paste all your function code for better understanding but:

  1. This is how you get the options from PickList in CRM 2011

    var myOptionSet = Xrm.Page.ui.controls.get("new_product")   //get Control
    var optionsSet = myOptionSet .getAttribute().getOptions();  //get Options
    preferredTimeOptionSet.clearOptions();                    //Clear all options
    //Create a new Option
    var opt1 = new Option();
    opt1.text = "one";
    opt1.value = 1;
    //Add Option
    //Remove Option

Good Example here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download