title: How to hide/show option sets based on other option sets CRM Dynamics
body: <p>One optionset defines the category with the right optionset. Then the second field displays only the related options. However I keep getting a loop when I step through it. I made an array with all of the right values and called them but I keep getting an error:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'toString' of undefined at Mscrm.TurboForm.Control.View.PicklistEditElement.addOption (<a href="https://ugcrmdev.crm9.dynamics.com/_static/form/formcontrols.js?ver=1659449427:24513:38" rel="nofollow noreferrer">https://ugcrmdev.crm9.dynamics.com/_static/form/formcontrols.js?ver=1659449427:24513:38</a>)" </p>
  </blockquote>
  
  <p>I don't know what I am doing wrong.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var generalServiceRequest = [100000000,100000001,100000002,100000003,100000004,100000005,100000006,100000007,100000008,100000009,100000010,100000011,100000012,100000013,100000014,100000015,100000016,100000017,100000018,100000019,100000020,100000021,100000022,100000023,100000024,100000025,100000026,100000027,100000028,100000029,100000030,100000031,100000032,100000033,100000034,100000035,100000036,100000037,100000038];
  var parksAndRec = [100000039,100000040,100000041,100000042,100000043,100000044,100000045];
  var boardOfPublicUtilities = [100000046,100000047,100000048,100000049,100000050,100000051];
  var publicWorks = [100000052,100000053,100000054,100000055,100000056,100000057,100000058,100000059,100000060,100000061,100000062,100000063,100000064,100000065,100000066,100000067,100000068,100000069,100000070,100000071,100000072,100000073,];
  var treasurer = [100000074,100000075,100000076,100000077,100000078,];
  var municipalCourt = [100000079,100000080,100000081,100000082,100000083,100000084,100000085,100000086,100000087,];
  var districtCourt = [100000088,100000089,100000090,100000091,100000092,100000093,100000094,100000095,];
  var neighborHoodResource = [100000096,100000097,100000098,100000099,100000100,100000101,100000102,100000103,100000104,100000105,];
  var sheriff = [100000106,100000107,100000108,100000109,100000110,];
  
  //OnLoad of form and OnChange of Specify field.
  
  function masterOptionSet() {
  
      resetOptionSet();
  
      var optionValue = Xrm.Page.getAttribute("new_specifyservicerequest").getValue();
      switch (optionValue) {
  
          case 100000000:
              showOptionSet(generalServiceRequest);
          break;
          case 100000001:
              showOptionSet(parksAndRec);
          break;
          case 100000002:
               showOptionSet(boardOfPublicUtilities);
          break;
          case 100000003:
               showOptionSet(publicWorks);
          break;
          case 100000004:
              showOptionSet(treasurer);
          break;
          case 100000005:
              showOptionSet(municipalCourt);
          break;
          case 100000006:
              showOptionSet(districtCourt);
          break;
          case 100000007:
              showOptionSet(neighborHoodResource);
          break;
          case 100000008:
              showOptionSet(sheriff);           
      }
  }
  
  function resetOptionSet()
  {   
      for(var i = 100000000; i &lt;= 100000110; i++){
  
          Xrm.Page.getControl("new_subjectmatter").removeOption(i);
      }
  }
  
  function showOptionSet(optionArray){
      for(var i = 0; i&lt; optionArray.length; i++){
          Xrm.Page.getControl("new_subjectmatter").addOption(optionArray[i]);
      }   
  }</code></pre>
  </div>
  </div>
  </p>