Jaa


Dynamic Picklist - Sub Industry based on Industry aka Cascading Picklists in Microsoft CRM

This contains sample code that demonstrates how to implement dynamic picklists on a custom entity. It creates a custom entity named “Dynamic Picklist Test” that contains Industry and Sub-Industry picklist fields. When a value for Industry is selected, the values in the Sub-Industry picklist field are filtered. If there are no sub-industries for an industry, the Sub-Industry field is disabled.

See how the Sub-Industry Field isn't even an option. :-)

The pick list for the accountants.

The picklist for the consulting industry.

 

The sample files are not intended to be used in a production environment without prior testing. You should deploy this sample to a test environment and examine it for interaction or interference with other parts of the system.

Click here for the download. And READ the ReadMe.doc file!!!

Comments

  • Anonymous
    February 08, 2006
    Ben -

    Did CRM drop the 'originalPicklistValues' property in the final release? - This sample code isn't working as expected -

    Do you know of any samples that are not subject to making the picklist values sequential? ie if industry = 1 then subindustry can be 3,9,12 or 15 - rather than limiting it to subindustry would be 1-5 -

    Thanks for providing the sample - Thanks for sharing.

    Scott.

  • Anonymous
    February 09, 2006
    Scott,
    I am not sure what feature that is. I didn't really touch the JScript until RTM....

    I am sure that what you want to do could be handled, it would just take a little bit more work...

    I am busy on about 3 different project that all end after Convergence, so hit me up after Convergence. :-)

    Thanks
    Ben

  • Anonymous
    July 25, 2006
    Hi,


    The error was as following "An error occurred when populating Microsoft CRM" can  tell me if 'originalPicklistOptions is this really valid for a picklist.



    Thanks for your time,
    Best regards,
    Michel DEGREMONT.

  • Anonymous
    November 09, 2006
    El otro día me plantearon esta cuestión ¿Cómo puedo hacer que los valores de un picklist (lista desplegable)

  • Anonymous
    November 10, 2006
    The comment has been removed

  • Anonymous
    February 21, 2007
    I would like to have multiple choice using Picklist so to choose more than one into a list Any ideas?

  • Anonymous
    March 28, 2007
    This is wonderful, my only questions are can this be applied to a 3rd level of picklists, so person choses a, which updates list b and when value from b is chosen it controls list c? and Where in your code do you actually assign which values are tied to to which values?

  • Anonymous
    May 08, 2007
    I can't download the zip file - is this link working?

  • Anonymous
    May 08, 2007
    I'd love to get a copy of this but I can't download the zip file and the code no longer seems to be available on this site.  Can someone help?

  • Anonymous
    May 11, 2007
    The comment has been removed

  • Anonymous
    May 21, 2007
    My personal website was down, which lead to this issue. :-) Back up...

  • Anonymous
    May 28, 2007
    You are right, there is an issue. What I did was quite different because I created my own example for this, but you can probley see here..  crmForm.all.new_item.origSelectedText = crmForm.all.new_item.SelectedText; And then later in my on change code, I basically made sure that if the new subset contained the same text, set a flag = to true, and also set a variable = to the DataValue of the field I wanted to remember. I then made the last statement, set the DataValue of the picklist to the value I temporarly stored. I can send some examples of my files if you want.

  • Anonymous
    June 05, 2007
    John Could you please email your code to correct the issue. Thanks

  • Anonymous
    August 22, 2007
    So with the values in place the second picklist default to the first item on the list, is there a way that a default can be set that the second list value is blank no matter what first value is selected?

  • Anonymous
    October 03, 2007
    Thanks for the review.  I have successfully implemented the code and now I have to manage changes to the lists.  How can I add to the list without having to keep the options in sequence?  For example items 1-5 are for A and 6-10 are for B,  But now the business want to add an additional item #11 for A. Taking this one step farther, perhps the solution above would allow me to "expire" a value.  For example #2 is no longer an option to be selected, but we want to show it and how it relates to older records. Thanks for the continued great content.

  • Anonymous
    October 23, 2007
    John Could you please email me also your code to correct the issue. Thanks

  • Anonymous
    October 23, 2007
    Hi sj, Could you please send me also the code on this issue. Thanks gabe

  • Anonymous
    October 24, 2007
    So I am still running into this issue: So with the values in place the second picklist default to the first item on the list, is there a way that a default can be set that the second list value is blank no matter what first value is selected? I have modfied the field names, to match the needs of our particular use, but no other changes to the code have been made.  Yet everytime I save the form that the fields are a part of, the second list reverts back to the first option associated with the first list. I did find that if I removed the {new_highlevel_onchange0()} from the main form code, that the value will stay but the low level list now shows all the values vs. the filtered values.

  • Anonymous
    December 10, 2007
    John Could you please email your code to correct the issue. Thanks

  • Anonymous
    February 08, 2008
    John and/or Ben, I am having the same issue with the secondary drop down reverting to the first value in the sub industry list when the entity is reopened. If you could email your code to correct this issue, I would greatly appreciate it.

  • Anonymous
    February 08, 2008
    OK so here is the code to fix the Sub Industry from shifting back to the first Sub Industry value when the record is re-opened.  There are two lines that need to be inserted into different parts of the Industry On Change Event script.  No changes need to be made to the Forms On Load event. Change 1: After: var oSubIndustry = crmForm.all.new_subindustry; Insert: var currentValue = oSubIndustry.DataValue; Change 2: After: oSubIndustry.Options = oTempArray; Insert: oSubIndustry.DataValue = currentValue; Here is the full on change code with the correction: // Get the Industry Element, since this event was fired by this element; the // event's "Source Element" will contain a reference to it. var oIndustry = crmForm.all.new_industry; // Initialize the Sub-Industry indexes var iStartIndex = -1; var iEndIndex = -1; // Depending on what the user selects in the Industry picklist, we will select // a range of options in the Sub-Industry picklist to display. // // For the purposes of this sample, it is assumed that the display text of each // Industry will be known and will not be localized. We have also ordered the // options in the Sub-Industry picklist so that they are group sequentially per // Industry. This allows the code to simply define start and stop Sub-Industry // indexes for each Industry. switch (oIndustry.SelectedText) { case "Accounting": iStartIndex = 1; iEndIndex = 5; break; case "Consulting": iStartIndex = 6; iEndIndex = 10; break; } // Get a reference to the Sub-Industry picklist element for later use var oSubIndustry = crmForm.all.new_subindustry; var currentValue = oSubIndustry.DataValue; // If the indexes where set, update the Sub-Industry picklist if (iStartIndex > -1 && iEndIndex > -1) { // Create a new array, which will hold the new picklist options var oTempArray = new Array(); // Initialize the index for the temp array var iIndex = 0; // Now loop through the original Sub-Industry options, pull out the // requested options a copy them into the temporary array. for (var i = iStartIndex; i <= iEndIndex; i++) { oTempArray[iIndex] = oSubIndustry.originalPicklistOptions[i]; iIndex++; } // Reset the Sub-Industry picklist with the new options oSubIndustry.Options = oTempArray; oSubIndustry.DataValue = currentValue; // Enable the Sub-Industry picklist for the user oSubIndustry.Disabled = false; } else { // The user has selected an unsupported Industry or no Industry oSubIndustry.DataValue = null; oSubIndustry.Disabled = true; }

  • Anonymous
    May 20, 2008
    Had someone got this script work properly? It works only for the first transition. When the user traverse more than once on the parent picklist, the scripts gives an error. I operate the script from the parent's Onchange editor of Dyanmics. var oIndustry = crmForm.all.new_parent_picklist; var iStartIndex = -1; var iEndIndex = -1; switch (oIndustry.SelectedText) { case "A": iStartIndex = 1; iEndIndex = 3; break; case "B": iStartIndex = 4; iEndIndex = 6; break; } var oSubIndustry = crmForm.all.new_child_picklist; var currentValue = oSubIndustry.DataValue; if (iStartIndex > -1 && iEndIndex > -1) { var oTempArray = new Array(); var iIndex = 0; for (var i = iStartIndex; i <= iEndIndex; i++) { oTempArray[iIndex] = oSubIndustry.Options[i]; iIndex++; } oSubIndustry.Options = oTempArray; oSubIndustry.DataValue = currentValue; oSubIndustry.Disabled = false; } else { oSubIndustry.DataValue = null; oSubIndustry.Disabled = true; }

  • Anonymous
    May 21, 2008
    Adrian, I have updated your code, and there is another script as well... do you have an email I can forward the scripts to?

  • Anonymous
    May 21, 2008
    Adrian, I have updated your code, and there is another script as well... do you have an email I can forward the scripts to?

  • Anonymous
    July 20, 2008
    Can someone please send me an updated version of this code. Michele can you please send that code. I cannot figure out how to get more than one transition without the error. Sincerely, Warren

  • Anonymous
    July 20, 2008
    Hehee....I forgot to put my email. Its frank_2910@hotmail.com -Warren

  • Anonymous
    July 23, 2008
    The comment has been removed

  • Anonymous
    July 25, 2008
    Thank you very much for the code Michele. It really helped a lot. Much appreciate it. Sincerely, Warren

  • Anonymous
    July 25, 2008
    Thank you very much for the code Michele. It really helped a lot. Much appreciate it. Sincerely, Warren

  • Anonymous
    August 04, 2008
    Hi, Where is the sourcecode for this, I tried the download link, but i didn't work. can someone sent it to me, or publish it on the web? Sincerely, Anders Email: music.anders.jeppesen@gmail.com

  • Anonymous
    November 26, 2008
    Can any one send me the script for 3 Level dynamic picklist Thanks in advance triggger@hotmail.com

  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/353041-need-a-little-client-side

  • Anonymous
    May 29, 2009
    PingBack from http://paidsurveyshub.info/story.php?title=east-region-microsoft-crm-dynamic-picklist-sub-industry-based-on