Thursday, July 12, 2012

MSCRM 2011: Setting the values of a Pick List (Option Set) based on another Pick List (Option Set)

A Client recently asked – Can an option set’s contents be dynamic and dependent on the option selected in another option set? The answer is absolutely “yes it can be done” and below are the steps.

There are multiple steps/tasks that must be performed in order to change the values of an Option Set based on a selection in another Option Set. In the Example below, we will assume that the first Option Set is for a list of Parts and the second Option Set is for a list of Sub-Parts for those Parts.

Task 1 – Create the two Option sets (Pick Lists) and include all of the possible options.  Add them to the entity form.

Task 2Create a new JavaScript Library (Web Resource) that will include the function to build a Pick List based on a value in another Pick List.

In the java script code below:
    • Replace “new_partspicklist” with the name of your first picklist.
    • Replace “newpartssubpicklist” with the name of your dynamic picklist.
    • In the line “if(picklistOneSelectedValue == "Part I")” replace Part I with your first selection.
    • In the line “if ( picklistTwo.Options[i].Text=="Part II – Brake " || picklistTwo.Options[i].Text=="Part II – Gear shift”  || picklistTwo.Options[i].Text=="Part II - Tire")” replace each value with the values you want to remove on your first selection.
    • You will have to repeat the steps above for each value you want to filter on. The “//” lines show where each filter block begin and end. You can copy/paste to add more for more values or remove blocks if you have fewer values. Make sure you add or remove the entire code block from beginning to end.

* Go to Settings, Customizations, Customize the system.

* Scroll Down to Web Resources, Click New from the toolbar.

* Enter the following Information in the New Web Resource Dialog:

* Name= “BuildSubPartPicklistBasedOnPart”

* Display Name= “Build Sub-Part Pick List Based on Part”

* Language = “English”

* Type = “Script (Jscript)”

* Click the Text Editor button

* Paste the following script in to the source dialog and make the changes described in the Note comments.

function PartPicklistOneOnchange(context) {
var picklistOneAttribute = "new_partspicklist"; // replace with your name of the first picklist

var picklistTwoAttribute = "new_partssubpicklist";  //replace with the name of the picklist with dynamic values

var picklistOne = document.getElementById(picklistOneAttribute);

var picklistTwo = document.getElementById(picklistTwoAttribute);

//Getting the selected value from Picklist One

var picklistOneSelectedValue = picklistOne.SelectedText

//This "if" statement stores the original values from the dynamic picklist.
            //Very important if the user hasn't made a selection on the first picklist or if the selection changes

if (picklistTwo.flag == true) {

picklistTwo.Options = picklistTwo.originalPicklistValues;




picklistTwo.originalPicklistValues = picklistTwo.Options;

picklistTwo.flag = true;


if (picklistOneSelectedValue != null) 


for (var i = picklistTwo.length - 1; i >= 0; i--) { 

    if (picklistTwo.Options[i].DataValue != null && picklistTwo.Options[i].DataValue != "")


    //BEGIN: If the picklist is set to Part I

    if(picklistOneSelectedValue == "Part I") {

      //Remove the values

      if ( picklistTwo.Options[i].Text=="Part II- Brake" || picklistTwo.Options[i].Text=="Part II - Gear Shift" || picklistTwo.Options[i].Text=="Part II - Tire")                  





    //END: Part I Selection     

    //BEGIN: If the picklist is set to Part II   

    if(picklistOneSelectedValue == "Part II") {

      //Remove these values 

      if ( picklistTwo.Options[i].Text=="Part I - Brake" || picklistTwo.Options[i].Text=="Part I - Gear Shift" || picklistTwo.Options[i].Text=="Part I - Tire")





     //END: Part II Selection

} //End function

* Click OK

* Click Save.

* Click Publish

* Click Save and Close

Task 3 -  Attach JScript function to onChange event handler

Next we need to setup the event handlers on the form being modified.

* Click on the Entities to expand.

* Select the Entity where the function will be called from and then click OK.

* Expand the Entity, choose Form and Information form type Main.

* Now that you are in the form editor we need to attach the event handler to the Field’s onChange event.

* Go to the field that will be changed and double-click. This will bring up the field properties dialog.

* Go to the Events tab and choose to Add a Forms Library

* The Web Resource Lookup will be displayed, choose the Web Resource added above and Click OK.

* In the Event Handler section Click Add.

* In the Handler Properties dialog do the following: Function = PartPicklistOneOnchange * Check Enabled
 *Check Pass execution context as first parameter
 *Click OK, to close the Handler Properties dialog

* Click OK, to close the Field Properties dialog

* Click Save and then Publish All Customizations.

Task 4 – Test your Changes.


sarahlee880 said...

All life demands struggle. Those who have everything given to them become lazy, selfish, and insensitive to the real values of life. The very striving and hard work that we so constantly try to avoid is the major building block in the person we are today. See the
link below for more info.

values @

Leslie Lim said...

I will keep your new article. I really enjoyed reading this post, thanks for sharing.


joy said...

We all need challenges in our life to keep motivated. I really had a great time scanning and reading your blog site and i was so amazed with your great artwork. I do hope you could inspire more readers. You can also visit my site for some interesting stuff.

sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made
in writing this article.

for IT the said...

Great Article
Java Online Training | Java EE course

Java Training in Chennai | J2EE Training in Chennai | java j2ee training institutes in chennai ~ Java Course in Chennai | Java Training Institutes in Chennai

Java 360 | IT Technical Articles |Java Training Institutes

for IT the said...

Great Article

HTML5 Online Training | JavaScript Training in Chennai | JavaScript Course | Javascript Online Course | Angularjs Training in Chennai | Backbone.JS Training in Chennai | Bootstrap Training in Chennai | Node.js Training in Chennai

Addison adolf said...

We are offering websites design service and much more!!!

Barbie Chiu said...

Thanks for sharing your article and for giving us the chance to read it. It is very helpful and encouraging. Visit my site too.

Addison adolf said...

woocommerce bulk sms Plugin for your online shopping store......

lee woo said...

Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.

Sourabh gupta said...

My Car Carrier from chandigarh to nagpur cost
My Car Carrier from lucknow to nagpur cost
My Car Carrier from Kolkata to nagpur cost
My Car Carrier from Hyderabad to nagpur cost
My Car Carrier from Bangalore to nagpur cost
My Car Carrier from pune to nagpur
My Car Carrier from Mumbai to nagpur cost
My Car Carrier from Chennai to nagpur cost
My Car Carrier from delhi to nagpur
My Car Carrier from Gurgaon to nagpur cost
My Car Carrier from Noida to nagpur
My Car Carrier from Faridabad to nagpur cost
My Car Carrier from Ahmedabad to nagpur cost
My Car Carrier from navi Mumbai to nagpur cost
My Car Carrier from thane to nagpur cost

Sourabh gupta said...

home relocation services from Ahmedabad to Lucknow charges
home relocation services from to chandigarh charges
home relocation services from rajkot to Lucknow charges
home relocation services from Rajkot to chandigarh charges
home relocation services from chandigarh to rajkot charges
home relocation services from Amritsar to surat charges
home relocation services from panchkula to Ludhiana charges
home relocation services from allahabad to varanasi charges
home relocation services from Kanpur to Bangalore charges
home relocation services from agra to Bangalore charges
home relocation services from Bangalore to agra charges
home relocation services chandigarh
home relocation services lucknow
home relocation services Vadodara
home relocation services Ahmedabad
home relocation services surat
home relocation services Rajkot

M Sunny said...

IVR definition Interactive Voice Response System and services are provided by virtually all businesses ,,visit sit e

Suraj Baba said...

Movers and Packers Hyderabad
Movers and Packers Bangalore
Movers and Packers Pune

Suraj Baba said...

Movers and Packers Mumbai
Movers and Packers Gurgaon
Movers and Packers Delhi

Suraj Baba said...

Movers and Packers Chennai
Movers and Packers Noida
Movers and Packers Navi Mumbai
Movers and Packers Thane
Movers and Packers Ghaziabad
Movers and Packers Faridabad

Suraj Baba said...

Movers and Packers in Hyderabad
Movers and Packers in Bangalore
Movers and Packers in Pune
Movers and Packers in Mumbai
Movers and Packers in Gurgaon
Movers and Packers in Delhi

Cindy Dy said...

Thank you for putting an effort to published this article. You've done a great job! Good bless!

hoa pikey said...

Great! Thanks for sharing the information. That is very helpful for increasing my knowledge in this fiel
Red Ball | | duck life | Slitherio
Red Ball 2 | Red Ball 3 | Red Ball 4

Relocate Services said...

Packers and Movers in Bangalore
Packers and Movers in Delhi
Packers and Movers in Jaipur
Packers and Movers in Pune