title: Issue getting value from dynamic option set (picklist) using Javascript in CRM 2011
body: <p>I am upgrading a CRM 4 solution to CRM 2011 and I am having an issue with a dynamic Option Set.</p>
  
  <p>I am populating the option set by calling an API from the Javascript. This returns a list of text and value options, which I then iterate through.</p>
  
  <p>Firstly, I retrieve the object itself and add a static Default option to the list:</p>
  
  <pre><code>var varPicklist = Xrm.Page.getControl("list_name");
  
  //Add a System Default option to the picklist
  var opt1 = new Option();
  opt1.text = "System Default";
  opt1.value = 100000;
  varPicklist.addOption(opt1);
  </code></pre>
  
  <p>I then iterate through the collection, create an object and add each one to the list:</p>
  
  <pre><code>//Populate the rest of the list
  var ObjectList = xmlDoc.getElementsByTagName("LookupItem");
  for (var i = 0 ; i &lt; ObjectList.length ; i++) 
  {
      var optValue
      var optText
      var ObjectListItems = ObjectList[i].childNodes;
      for (var j = 0 ; j &lt; ObjectListItems.length ; j++)
      {
          var value = ObjectListItems[j].childNodes[0];
          if (ObjectListItems[j].nodeName == "Key")
          {
              optValue = value.nodeValue;
          }
          else if (ObjectListItems[j].nodeName == "Value")
          {
              optText = value.nodeValue;
          }
      }
  
  var opt = new Option();
  opt.text = optText;
  opt.value = optValue;
  varPicklist.addOption(opt);
  };
  </code></pre>
  
  <p>As stated, this all seems to work. The Picklist gets populated with the values and doesn't error. If I stick an alert in there during this process, the correct values or labels are displayed.</p>
  
  <p>However, somehow the items seem to get lost along the way. If I try to reference them in any way from elsewhere in the form, I get null back. I tried this;</p>
  
  <pre><code>Xrm.Page.getAttribute("list_name").getSelectedOption().value
  </code></pre>
  
  <p>...and this;</p>
  
  <pre><code>Xrm.Page.getAttribute("list_name").getValue();
  </code></pre>
  
  <p>Neither of which worked. I tried accessing the text as opposed to the values (just as a test) and couldn't get those either. </p>
  
  <p>But when I tried the same methods with option sets which contained static options, I could access them no problem.</p>
  
  <p>Any help with where I'm going wrong would be appreciated...</p>