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());
    });
}

This way they appeared in the option list but when you selected one of them the option text was not shown and the value also wasn't available on save.

After some looking around I discovered that you cannot just add any text/value combination but it has to be an existing option from CRM. So after adding 4 test options in CRM...

... I was able to first remove them with clearOptions and after that add 3 of them to prove it worked this way.

function OnLoad() {

    Xrm.Page.getControl("new_optionset").clearOptions();

    Xrm.Page.getControl("new_optionset").addOption({ text: "One", value: 100000000 });
    Xrm.Page.getControl("new_optionset").addOption({ text: "Two", value: 100000001 });
    Xrm.Page.getControl("new_optionset").addOption({ text: "Four", value: 100000003 });

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

Now you can see the 3 options I added and you are able to select them as well

Comments (5) -

  • resume writing service

    1/5/2017 4:20:45 AM |

    It is nice to read your post and you give wonderful information. Please keep posting such kind of informative stuff. Interesting article share and this blog is impresses more people to reading that blog.

  • more information

    4/3/2017 7:44:45 AM |

    Thanks for sharing this issue! I really like the way how you work! The problem is now fixed, and all remained to be happy! Use our website for your individual writing needs. God bless you!

  • testimonials

    4/4/2017 9:40:55 PM |

    I never used this code when I wrote my site! It seems to me that this is not a lot of wrong lines

  • custom essay writing service

    5/17/2017 8:09:40 AM |

    I want to add this option to my site, it seems to me that it will improve it and be easy to use

Loading