web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Dependent Option Set for Cascading Picklist in Office 365 CRM online error(s)

(0) ShareShare
ReportReport
Posted on by

Hello all,

I hope all is well with you.

I have created a pick list within CRM Online.

There will be 3 boxes that will have choices (see in yellow within the screen shot)

   General Business Unit (Parent)

   Business Line (Child)

   Market Segment (Dependent Option Set)

Though my Form loads correctly (OnLoad), when I click on the General Business unit tab (OnChange) in my Final Prospects form (within the DEV sandbox), I receive the following error.

script_5F00_error4.PNG

What am I doing wrong, please?

Below is the code for my web resources.

[
  {
      "parent": "GBU",
      "child": "Business_Line",
      "options": {
          "127000000": [
              "227000000",
              "227000001",
              "227000002",
	      "227000003",
	      "227000004"
          ],
          "127000001": [
              "227000005",
              "227000006",
              "227000007",
              "227000008"
          ]
      }

  },
  {
      "parent": "Business_Line",
      "child": "Market_Segment",
      "options": {
          "227000000": [
              "327000000",
              "327000001",
              "327000002",
	      "327000003",
              "327000004",
	      "327000005",
              "327000006",
              "327000007",
              "327000008",
	      "327000009",
              "327000010",
              "327000011",
	      "327000012"
          ],
	  "227000001": [
              "327000000",
              "327000001",
              "327000002",
	      "327000003",
              "327000004",
	      "327000005",
              "327000006",
              "327000007",
              "327000008",
	      "327000009",
              "327000010",
              "327000011",
	      "327000012"
          ],
   	  "227000002": [
              "327000000",
              "327000001",
              "327000002",
	      "327000003",
              "327000004",
	      "327000005",
              "327000006",
              "327000007",
              "327000008",
	      "327000009",
              "327000010",
              "327000011",
	      "327000012"
          ],
	  "227000003": [
              "327000000",
              "327000001",
              "327000002",
	      "327000003",
              "327000004",
	      "327000005",
              "327000006",
              "327000007",
              "327000008",
	      "327000009",
              "327000010",
              "327000011",
	      "327000012"
          ],
    	  "227000004": [
              "327000000",
              "327000001",
              "327000002",
	      "327000003",
              "327000004",
	      "327000005",
              "327000006",
              "327000007",
              "327000008",
	      "327000009",
              "327000010",
              "327000011",
	      "327000012"
          ],
          "227000005": [
              "327000013",
              "327000014",
              "327000015",
	      "327000016",
              "327000017"
          ],
          "227000006": [
              "327000013",
              "327000014",
              "327000015",
	      "327000016",
              "327000017"
          ],
          "227000007": [
              "327000013",
              "327000014",
              "327000015",
	      "327000016",
              "327000017"
          ],
          "227000008": [
              "327000013",
              "327000014",
              "327000015",
	      "327000016",
              "327000017"
          ],
      }
  }
]


_______________________________________________________________________________________________________________

// =====================================================================
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
// =====================================================================


//If the SDK namespace object is not defined, create it.
if (typeof (SDK) == "undefined")
{ SDK = {}; }
// Create Namespace container for functions in this library;
SDK.DependentOptionSet = {};
SDK.DependentOptionSet.config = null;

/**
 * @function SDK.DependentOptionSet.init
 * @param {string} webResourceName the name of the JavaScript web resource containing the JSON definition 
 * of option dependencies
 */
SDK.DependentOptionSet.init = function (new_GBU_Ticket_Script) {
    if (SDK.DependentOptionSet.config == null) {
        //Retrieve the JavaScript Web Resource specified by the parameter passed
        var clientURL = Xrm.Page.context.getClientUrl();

        var pathToWR = clientURL + "/WebResources/" + new_GBU_Ticket_Script;
        var xhr = new XMLHttpRequest();
        xhr.open("GET", pathToWR, true);
        xhr.onreadystatechange = function () {
            if (this.readyState == 4 /* complete */) {
                this.onreadystatechange = null;
                if (this.status == 200) {
                    SDK.DependentOptionSet.config = JSON.parse(this.response);
                    SDK.DependentOptionSet.completeInitialization();
                }
                else {
                    throw new Error("Failed to load configuration data for dependent option sets.");
                }
            }
        };
        xhr.send();
    }
    else {
        SDK.DependentOptionSet.completeInitialization();
    }
};

/**
 * @function SDK.DependentOptionSet.completeInitialization
 * Initializes the dependent option set options when the form loads
 */
SDK.DependentOptionSet.completeInitialization = function () {
    //If the parent field is null, make sure the child field is null and disabled
    // Otherwise, call fireOnChange to filter the child options
    for (var i = 0; i < SDK.DependentOptionSet.config.length; i++) {
        var parentAttribute = Xrm.Page.getAttribute(SDK.DependentOptionSet.config[i].parent);
        var parentFieldValue = parentAttribute.getValue();
        if (parentFieldValue == null || parentFieldValue == -1) {
            var childAttribute = Xrm.Page.getAttribute(SDK.DependentOptionSet.config[i].child);
            childAttribute.setValue(null);
            childAttribute.controls.forEach(function (c) { c.setDisabled(true); });
        }
        else {
            parentAttribute.fireOnChange();
        }
    }
}

/**
 * @function SDK.DependentOptionSet.filterDependentField
 * Locates the correct set of configurations
 * @param {string} parentFieldParam The name of the parent field
 * @param {string} childFieldParam The name of the dependent field
 */
SDK.DependentOptionSet.filterDependentField = function (parentFieldParam, childFieldParam) {
    //Looping through the array of all the possible dependency configurations
    for (var i = 0; i < SDK.DependentOptionSet.config.length; i++) {

        var dependentOptionSet = SDK.DependentOptionSet.config[i];

        /* Match the parameters to the correct dependent optionset mapping*/
        if ((dependentOptionSet.parent == parentFieldParam) &&
            (dependentOptionSet.child == childFieldParam)) {

/*
* Using setTimeout to allow a little time between calling this potentially recursive function.
* Without including some time between calls, the value at the end of the chain of dependencies 
* was being set to null on form load.
*/
            setTimeout(SDK.DependentOptionSet.filterOptions,
                100, parentFieldParam,
                childFieldParam,
                dependentOptionSet);
        }
    }
};

/**
 * @function SDK.DependentOptionSet.filterOptions
 * Filters options available in dependent fields when the parent field changes
 * @param {string} parentFieldParam The name of the parent field
 * @param {string} childFieldParam The name of the dependent field
 * @param {object} dependentOptionSet The configuration data for the dependent options
 */
SDK.DependentOptionSet.filterOptions = function (parentFieldParam, childFieldParam, dependentOptionSet)
{
    /* Get references to the related fields*/
    var parentField = Xrm.Page.getAttribute(parentFieldParam);
    var parentFieldValue = parentField.getValue();
    var childField = Xrm.Page.getAttribute(childFieldParam);
    /* Capture the current value of the child field*/
    var currentChildFieldValue = childField.getValue();
    /* If the parent field is null, set the Child field to null */
    //Interactive Service Hub, CRM for Tablets & CRM for phones can return -1 when no option selected
    if (parentFieldValue == null || parentFieldValue == -1) {
        childField.setValue(null);
        childField.fireOnChange(); //filter any dependent optionsets
        // Any attribute may have any number of controls
        // So disable each instance
        childField.controls.forEach(function (c) {
            c.setDisabled(true);
        });
        //Nothing more to do when parent attribute is null
        return;
    }

    //The valid child options defined by the configuration
    var validOptionValues = dependentOptionSet.options[parentFieldValue.toString()];

    //When the parent field has a value
    //Any attribute may have more than one control in the form,
    // So iterate over each one
    childField.controls.forEach(function (c) {
        c.setDisabled(false);
        c.clearOptions();
        //The attribute contains the valid options
        var childFieldAttribute = c.getAttribute();

        //The attribute options for the Interactive Service Hub, CRM for Tablets & 
        // CRM for phones clients do not include a definition for an unselected option.
        // This will add it
        if (Xrm.Page.context.client.getClient() == "Mobile") {
            c.addOption({ text: "", value: -1 });
        }

        //For each option value, get the definition from the attribute and add it to the control.
            validOptionValues.forEach(function (optionValue) {
                //Get the option defnition from the attribute
                var option = childFieldAttribute.getOption(parseInt(optionValue));
                //Add the option to the control
                c.addOption(option);
            })
    });
    //Set the value back to the current value if it is a valid value.                
    if (currentChildFieldValue != null &&
        validOptionValues.indexOf(currentChildFieldValue.toString()) > -1) {
        childField.setValue(currentChildFieldValue);
    }
    else {
        //Otherwise set it to null
        childField.setValue(null);
        childField.fireOnChange(); //filter any other dependent optionsets
    }
}





GBU2_5F00_Handler.PNG

GBU_5F00_Handler1.PNG

Please let me know what you think.

Peace.

Jon F. Ginsberg

*This post is locked for comments

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at

    Hi,

    try with my dependent optionset solution, you can download from here:

    crmoptionsets.azurewebsites.net

    you wrote CRM Online, if you are using Dynamics 365 v8.2 you can use the CRM 2016 download link, if you are already in Dynamics 365 v9 use the download for that version.

    the site I linked has a demo, you can test how it works before installing it

  • Community Member Profile Picture
    on at

    Hello Guido,

    thank you for your quick response.  Unfortunately, my client does not allow me to install 3rd party solutions, including bootstrap and git references.

    I had used the Microsoft web resources for my example, already.

    msdn.microsoft.com/.../gg594433.aspx

    Also, I have been directed to use JS and not xml, as we have CRM 2016 and intend on using this (our new template) in other Enterprise Applications.

    I am still needing some .js support on this.

    Please advise.

    Sincerely and most cordially,

    Jon F. Ginsberg

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    Hi Jon,

    I can understand you client policy, but when you add the msdn sample you are adding 3rd party code.

    I looked at your screenshot and the problem is with the field names, they are wrong because you need to use the logicalname

    Said that, you can still use my solution (that use JSON and not XML)

    First of all download the solution, extract the zip file and find the file called

    WebResources\gp_jsDependentOptionSetjsF954C1D0-DE6A-E611-80DD-FC15B4286740

    it contains the JS file that you can put inside your custom JS webresource instead of the SDK content.

    the only difference with the SDK sample is the name of the function, so instead of

    SDK.DependentOptionSet.init you need to call the DO.DependentOptionSet.init

    and instead of

    SDK.DependentOptionSet.filterDependentField you need to call the DO.DependentOptionSet.filterDependentField

    Now, you need to create a valid JSON file, or you do manually (making sure the logicalname are correct) or you can

    1) install my solution

    2) use my solution to edit your JSON file

    3) uninstall my solution

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    also, I noticed you updated the script to call directly your JSON file instead of putting in as parameter, as you wrote the code you still need add the parameter as the function because you just renamed the parameter and not setting a value.

  • Suggested answer
    John Clark Profile Picture
    400 on at

    Hi Jon,

    As an alternative (and in my mind, simpler) approach, did you consider simply creating a set of three "linked" custom entities instead of all your JavaScript? You could then rely on the form's Related Records Filtering functionality to control the available selection of list items. You'd then only need some simple JavaScript for clearing the child record(s) when their parent is changed. By using custom entities for your "lookup lists" you also get the added benefit of being able to easily add and deactivate list items, without changing any code - clients always change their minds eventually.

    We use this approach all the time for clients, for things like multi-level lead source, industries, etc.

    Cheers,

    John

  • Verified answer
    Community Member Profile Picture
    on at

    Hello Guido,

    thank you very much for your advice and your specialized tool.

    I was able to use your tool, which made creating the JSON file a lot easier, as well as assisting in our debugging.

    Ultimately, we used a combination of your tool and also Microsoft's sample solution to create our pick lists.

    Your time and efforts are greatly appreciated.

    Sincerely and most cordially,

    Jon F. Ginsberg

  • Testuser12 Profile Picture
    270 on at

    Hi guys,

    Need a bit of stir on this one.  I have a very basic two field dependency on my Dynamics 365 Opportunity form.

    I have used the Microsoft Sample SDK and also Guido sample SDK, both combined with Guido JSON generator and i still get the original message that Jon experienced.

    Would you be able to shine any more light on your working solution Jon, or Guido do you anything else you could advise me on.

    Happy to provide screenshots of my libraries, form properties etc.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans