January 14, 2019

getText API behavior changed

Some days ago I was upgrading some JavaScript files to v9 and I noticed one of the scripts was not working correctly.
The specific code was using the getText function in order to retrieve the label of an optionset field. The getText function used to return an empty string in Dynamics instances prior to CRM 2016, but in recent versions it returns null. If you need to handle the label in your code (like showing some alerts) the check should be like this one:
function checkOptionsetLabel(context, fieldName) {
    var selectedLabel = context.getAttribute(fieldName).getText();
    if (selectedLabel != null) {
        // ...
    }
}
Also the official documentation has been updated to highlight the return value. Hope it helps!