CRM 2013 Add Option Issue Javascript RRS feed

  • Question

  • Hi All,

    I have been trying to add new options to an empty option set field using a JavaScript on the form on Load.However,when I try to change the options the new options tend to disappear on change.The selected option text and value becomes null on change.I have used SDK supported method,still the issue persists.Any suggestions?

    Saturday, August 2, 2014 7:44 PM

All replies

  • Hi, 

    Have you tried debugging your javascript? can you post your code snippet? only after looking at your code we can tell what could possibly be wrong 


    Vishal Pandey MS Dynamics CRM Developer

    Sunday, August 3, 2014 4:46 PM
  • Hi,

     The issue may be because your option set is reinitialized to empty option set when form/data refreshes. Please try to look into alternate approach.

    1. on design time, store all possible values into the option set.

    2. on form load, iterate thru the option set and remove the ones that you do not need.

    This same approach is used in dependent option set sample in SDK. Please take a look to see if it is suitable for your needs.



    Monday, August 4, 2014 2:56 AM
  • Hi,

    Thanks for the response.I cannot store the values at design time since the values are dynamic and based on a different records value.I have posted my code above.



    Monday, August 4, 2014 7:39 AM
  • Hi,

    It is important to remember that, when you work with an option-set control, you can only manipulate available options but you cannot create new options.

    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, August 4, 2014 10:25 AM
  • Hello,

    I am sorry, But I am not able to read much from the code you have provided. But looking at the problem description I feel that you are trying to change option set values from on change of option set. This is what you would have to do (in general)

    1. on Form load, load your dynamic option set

    2. on some other field change (NOT ntt_wrapcode control), load dynamic value for "ntt_wrapcode" control.

    3. on change of "ntt_wrapcode", get the selected text.

    if my assumptions are not correct, please update me with the code for formload and code for on change and some sample data.



    Monday, August 4, 2014 12:05 PM
  • Hello Friend,

    Ravitheja was correct when he said that one could only manipulate existing option set.

    Here is what i did.

    I create a new form

    added a new option set with three items - values 100000000 :text=item, 10000001:text=item1, 100000002:text=item2.

    then wrote the following function

    function form_onLoad() {
    function createOptionSet() {
        var wrap_Control = Xrm.Page.ui.controls.get("new_wrapcode");
        var option0 = { value: 100000000, text: "Zero" };
        var option1 = { value: 100000001, text: "One" };
        var option2 = { value: 100000002, text: "Two" };
        var option3 = { value: 100000003, text: "Three" };
        var option4 = { value: 100000004, text: "Four" };
        var option5 = { value: 100000005, text: "Five" };
    function onChange() {

    on change alerted correct values when i selected "Zero, One, Two" and threw error message when i selection three, four, five.

    So the blank option set that you are setting up is the issue here. if you create 10 default items into your option, you can replace them with 10 dynamic values or less - nothing more.

    Hope that helps. It is a learning for me. Thanks Mate.



    Monday, August 4, 2014 1:22 PM
  • Hi Jithesh,

    By keeping the option set value same are you able to replace the labels only? since the label text has to be dynamic in my case.



    Monday, August 4, 2014 1:27 PM
  • For the record, the above script I posted changes the option list text.

    But as soon as the item is selected from the list, the text reverts back to the option set at design time.



    Wednesday, August 6, 2014 12:08 AM
  • Yes,that is what my issue is.I want to retain the new options on change also.
    Wednesday, August 6, 2014 6:30 AM
  • Hi,

    I tried the above code for dynamically removing values from "statuscode" (status reason) on Lead, but getting error-

    Error: Object doesn't support Property or Method "clearOptions"

    • Edited by Rizwan Aarif Thursday, October 1, 2015 5:04 AM re-phrased
    Thursday, October 1, 2015 5:04 AM