Posted in CRM, JavaScripts, XML

Dependent Picklist / OptionSet in CRM 2016

Dependent Picklist / OptionSet in CRM 2016

In a recent scenario, I was asked to create a dependent Pick-list/ Option set list where the options of Second Pick-list are dependent on the Value of the First one. By default there is no such option in Dynamics CRM but I came up with a solution from SDK.

I’m going to share the steps in detail for the solution here :-

Step1-

Create a Webresource of type Jscript  with name “SDK.DependentOptionSet.js” and upload the JScript file from SDK -> SsmpleCode -> JS -> FormScripts -> SDK.DependentOptionSet.js

By default it is available in CRM SDK.

1.JPG

Step2:-

Create Another Web resource of type XML with name- “new_dependentoptionsetxml

3.JPG

Step 3:-

Modify the XML based upon your options from Parent optionSet and Dependent optionSet

In my case the XML is like the following:-

<!---->
<!--<snippetTicketDependentOptionSetConfig.xml>-->
<DependentOptionSetConfig enity = "account">
<ParentField id = "new_category" label="Category">
<DependentField id="new_subcategory" label="Sub Category" />
    <Option value="1" label="Gold">
        <ShowOption value="1" label="gold1" />
        <ShowOption value="2" label="gold2" />
        <ShowOption value="3" label="gold3" />
        <ShowOption value="4" label="gold4" />
    </Option>
    <Option value="2" label="Silver">
       <ShowOption value="5" label="silver1" />
       <ShowOption value="6" label="silver2" />
       <ShowOption value="7" label="silver3" />
       <ShowOption value="8" label="silver4" />
    </Option>
    <Option value="3" label="Diamond">
       <ShowOption value="9" label="dialmond1" />
       <ShowOption value="10" label="diamond2" />
       <ShowOption value="11" label="dialmond3" />
       <ShowOption value="12" label="diamond4" />
    </Option>
 </ParentField>
 </DependentOptionSetConfig>
 <!--</snippetTicketDependentOptionSetConfig.xml>-->

 
<!---->

Step 4 :-

Attach the Library and add the function on OnLoad event of the Form for the “new_SDK.DependentOptionSet.js” :

Function :-  SDK.DependentOptionSet.init

Parameter :- “new_dependentoptionsetxml (its basically the xml that we created before)

5.JPG

Step 5 :-

Add the function at onChage Event of the First OptionSet / Picklist

Function :- SDK.DependentOptionSet.filterDependentField

Parameter :- “new_category”,”new_subcategory”

6.JPG

Now You’re done. After Publishing all the changes, when you first open the record you’ll get the dependent picklist / OptionSet as ReadOnly.

7

After the selection of the Parent Picklist, the Dependent picklist will show the dependent values.

8.JPG

That’s it Enjoy:-))

Advertisements

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