Wednesday, 27 September 2017

Create dependent optionsets in MS Dynamics CRM


 This blog is based on sample code provided by Microsoft and can be reviewed in the SDK located \SDK\SampleCode\JS\FormScripts.
Recently I have got a requirement to filter the value of one option set field by a value chosen in another option set field. This is not an out of box features of CRM so we have to implement this functionality using web resources.
Below are steps to create dependent option set:-
1.     Create both parent and child option set field and insert their all options.
2.     Create a Webresource of type Jscript and upload the JScript file from
   SDK -> SsmpleCode -> JS -> FormScripts -> SDK.DependentOptionSet.js
3.      Create Another Webresource of type XML and upload the XML file from
  SDK -> SsmpleCode -> JS -> FormScripts -> DependentOptionSetConfig.xml
Modify the XML based upon your options from Parent optionSet and Dependent optionSet
<!--<snippetDependentOptionSetConfig.xml>-->
<DependentOptionSetConfig entity="account" >
<ParentField id="new_parent"
           label="Parent">
<DependentField id="new_child"
               label="Child" />
<Option value="1"
       label="India">
<ShowOption value="1"
            label="New Delhi" />
<ShowOption value="2"
            label="Mumbai”/>
<ShowOption value="3"
            label="Patna”/>
</Option>
<Option value="2"
       label="USA">
<ShowOption value="4"
            label="New Jersy” />
<ShowOption value="5"
            label="Newyork" />
<ShowOption value="6"
            label="Texas” />
</Option>
<Option value="3"
       label="United Kingdom">
<ShowOption value="7"
            label="London" />
<ShowOption value="8"
            label="Amsterdom" />
<ShowOption value="9"
            label="Paris" />
</Option>
</ParentField>
</DependentOptionSetConfig>
<!--</snippetDependentOptionSetConfig.xml>-->
4.     Attach the JS Liabrary and add below function on OnLoad event of the Form and pass the config xml as parameter.
Function :-  SDK.DependentOptionSet.init
Parameter :- “new_DependentOptionSetConfig.xml
5.     Add below function at onChage Event of the parent OptionSet
Function :- SDK.DependentOptionSet.filterDependentField 
Parameter :- “new_parent”,”new_child”
6.     Now publish all the changes and open any related record.
7.     After the selection of the Parent optionset, the Dependent optionset will show the dependent values.
Hope this was helpful.
Thanks


No comments:

Post a Comment

Have you ever faced an issue where you need to import some record without changing GUID of the record? For example if we need to migr...