I am currently working on an upgrade project Dynamics 2011->2016 and for the following piece of code, it seems that in Dynamics 2016 the addOption() function does not work if the value is not already defined in the optionset. Using the code below does add the value to the optionset but the option cannot be selected! Is there a way to work around this issue without having to add the options statically in the field's optionset ?
PopulateCaseTemplateRecords = function () {
//Fetch case template records
var fetchXml =
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
+ "<entity name='new_casetemplate'>"
+ "<attribute name='new_name' />"
+ "<filter type='and'>"
+ "<condition attribute='statecode' operator='eq' value='0' />"
+ "<condition attribute='ownerid' operator='eq-userteams' />"
+ "</filter>"
+ "</entity>"
+ "</fetch>";
//retrieve case templates using asynch call to webapi v8.0
return WebAPI.Proxy.Fetch("new_casetemplates", fetchXml).then(function (retrievedCaseTemplate) {
if (retrievedCaseTemplate) {
if (retrievedCaseTemplate.length >= 1) {
Xrm.Page.getControl("new_case_template").clearOptions();
//Populate the Case template option set on Case
for (var i = 0; i < retrievedCaseTemplate.length; i++) {
var option = new Option();
option.text = retrievedCaseTemplate[i].new_name;
option.value = i;
//Add the new option, Does not work in Dynamics 2016 if option not defined in optionset!
Xrm.Page.getControl("new_case_template").addOption(option);
}
}
}
});
}