I am working on upgrading CRM 2015 to 2016 and running into issues.
I use web resources to convert textbox to dropdown on my forms especially for country and state fields.
I modified my code while upgrading from CRM4 to CRM2015 but it again broke on me.
Below is the code snippet. Please help.
function wireUpDropDown(countryFieldName, Countries) {
var $countryField = $('#' + countryFieldName);
if ($countryField.length < 1) return;
$countryField.hide();
//var selectedCountry = $countryField.val();
var selectedCountry = Xrm.Page.getAttribute(countryFieldName).getValue();
var countryRequirementLevel = Xrm.Page.getAttribute(countryFieldName).getRequiredLevel();
countryRequirementLevel = countryRequirementLevel == "required" ? 2 : countryRequirementLevel == "recommended" ? 1 : 0;
//var $countryDropdown = generateSelectBox('ddl_' + countryFieldName, countryRequirementLevel, Countries, selectedCountry);
var $countryDropdown = generateSelectCountry('ddl_' + countryFieldName, countryRequirementLevel, Countries, selectedCountry);
$('#' + countryFieldName + '_d').append($countryDropdown);
$countryDropdown.change({ 'countryFieldName': countryFieldName }, handleChangedCountry);
document.getElementById('ddl_' + countryFieldName).tabIndex = document.getElementById(countryFieldName).tabIndex;
//LoadStateField(stateFieldName, selectedCountry);
}
// Sets the value of the country field to the newly selected value and reconfigures the dependent state dropdown.
function handleChangedCountry(eventData) {
// var stateFieldName = eventData.data.stateFieldName;
var selectedCountry = setFieldFromDropdownData(eventData.data.countryFieldName);
//LoadStateField(stateFieldName, selectedCountry);
}
// Sets a field's value based on a related dropdown's value
function setFieldFromDropdownData(fieldName) {
var $dropdown = $('#ddl_' + fieldName);
if ($dropdown.length != 1) return null;
var selectedValue = $dropdown.find('option:selected:first').val();
var attr = Xrm.Page.getAttribute(fieldName);
if (attr != null) attr.setValue(selectedValue);
return selectedValue;
}
// Generates a new select box with appropriate attributes for MS CRM 2011.
function generateSelectCountry(id, requirementLevel, options, selectedValue) {
var $ddl = $('<select id="' + id + '" class="ms-crm-SelectBox" req="' + requirementLevel + '" height="4" style="IME-MODE: auto; width: 100%"></select>');
$ddl.append(jQuery('<option></option').val('').html(''));
$.each(options, function (i, item) {
$ddl.append(jQuery('<option></option').val(item.name).html(item.name));
//$ddl.append(jQuery('<option></option').val(item.abbr).html(item.name));
if (selectedValue == item.name)
// if (selectedValue == item.abbr)
$ddl.find('option:last').attr('selected', 'selected');
});
return $ddl;
}