Filter OptionSets based on Selection in MS CRM using Javascript

One of our friend requested me to help on the below requirement, Change Option Sets based on parent option set value selection,

Option Set Names

Follow the below steps,

Step 1: For this example I am using Contact entity. Open Contact Form.

Step 2: Create First Option Set field,

Display Name: Category
Name: new_category
Options:
Label: Ice Cream & Value: 100000000
Label: Soft Drinks & Value: 100000001

Category OptionSet
Step 3: Create Second Option Set field,

Display Name: Sub Category
Name: new_subcategory
Options:
Label: Amul & Value: 100000000
Label: Baskin Robins & Value: 100000001
Label: Kwality Wall’s & Value: 100000002
Label: Coca Cola & Value: 100000003
Label: Sprite & Value: 100000004
Label: Pepsi & Value: 100000005

SubCategory OptionSet

Step 4: Click Here to Download XML and create Data (XML) Web Resource (new_CategoryOptionSetConfig.xml)

Category Option Set Configurations XML

Save and Publish the Web Resource.

Step 5: Click Here to download Java Script Code and create new JScript Web Resource (new_ SampleOptionsSet.Js),
Sample Options Set JS
Save and Publish the Web Resource.

Step 6: Open Contact form. Drag and Drop the Category and Sub Category Optionset fields on the Contact Form.
Contact Form

Step 7: Click on Contact Form Properties.

  1. Add new_SampleOptionSet.js to the Form Libraries.
  2. Add Function SDK.DependentOptionSet.init on Form OnLoad.
  3. Copy and paste the parameter “new_CategoryOptionSetConfig.xml”, in Comma separated list of parameters…and click on OK. (Remove commas and enter manually)
  4. Onload Sample Option Set JS

    Onload Sample Option Set JS Add Function

  5. Double click on Category Option Set field. Add Function SDK.DependentOptionSet.filterDependentField on Onchange Event.
  6. Category OnChange Event

  7. Add Parameters (“new_category”,”new_subcategory”) in Comma separated list of parameters…and click on OK. (Remove commas and enter manually)
  8. Add Parameters to Sample Option Set On Category

    Save and Publish the Contact Form.

    Step 8: Open any New/ Existing Contact record to check below OptionSet behavior on selection,
    Output

    Please provide your valuable comments on this article.
    Source: MSDN

    Advertisements

5 thoughts on “Filter OptionSets based on Selection in MS CRM using Javascript

  1. I am not getting open the XML and script code in the links. can you please provide another source or code… in detail…

    Thanks in advance.

    Like

  2. Instead of using xml, which is hard to understand and maintain especially for business users, we’ve adopted to use action which returns a comma delimited valid optionset values. Action also helps if your rules involve attribute values from multiple entities.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s