I am upgrading a CRM 4 solution to CRM 2011 and I am having an issue with a dynamic Option Set.
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.
Firstly, I retrieve the object itself and add a static Default option to the list:
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);
I then iterate through the collection, create an object and add each one to the list:
//Populate the rest of the list
var ObjectList = xmlDoc.getElementsByTagName("LookupItem");
for (var i = 0 ; i < ObjectList.length ; i++)
{
var optValue
var optText
var ObjectListItems = ObjectList[i].childNodes;
for (var j = 0 ; j < 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);
};
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.
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;
Xrm.Page.getAttribute("list_name").getSelectedOption().value
...and this;
Xrm.Page.getAttribute("list_name").getValue();
Neither of which worked. I tried accessing the text as opposed to the values (just as a test) and couldn't get those either.
But when I tried the same methods with option sets which contained static options, I could access them no problem.
Any help with where I'm going wrong would be appreciated...