Options added via addOption() appear in the list but cannot be selected

Today I was trying to solve a little mystery for a colleague of mine. She was trying to dynamically add options to an empty option list in CRM 2015. The following code was used to do so:

function OnLoad() {

    Xrm.Page.getControl("new_optionset").addOption({ text: "One", value: 1 });
    Xrm.Page.getControl("new_optionset").addOption({ text: "Two", value: 2 });
    Xrm.Page.getControl("new_optionset").addOption({ text: "Three", value: 3 });
    Xrm.Page.getControl("new_optionset").addOption({ text: "Four", value: 4 });

    Xrm.Page.getAttribute("new_optionset").addOnChange(function () {
        alert(Xrm.Page.getAttribute("new_optionset").getValue());
    });
}

More...

CRM Solution Manager - A must have tool for CRM developers

When I started as a CRM developer I used to make changes to JavaScript, went to the form editor of the entity concerned, clicked form properties, opened up the JavaScript, pasted the changed code, clicked save and publish and the went back to my browser to refresh the page and see if the change was working.

You can imagine that if you keep doing this months on end you will get RSI for sure!

More...