locked
CRM 2011 - Javascript optionsets error RRS feed

  • Question

  • Hi Everyone,


    Can anyone assist me with the below javascript code, I keep getting errors onchange event (see below image). I'm no expert on JS but I have enough knowledge to get by, but this Is causing me problems. It only errors when I select value 1 "Yes".


    Any assistance would be greatly appreciated.


    Regards
    Paul

    function allowance_test()
    {
        if(Xrm.Page.getAttribute("value1").getSelectedOption() != null){
        if(Xrm.Page.getAttribute("value1").getSelectedOption().text =="Yes")

       {
        Xrm.Page.getAttribute("value2").setRequiredLevel("required");
        Xrm.Page.getAttribute("value2").setRequiredLevel("required");
       }
     if(Xrm.Page.getAttribute("value1").getSelectedOption().text =="No")

       {
        Xrm.Page.getAttribute("value3").setRequiredLevel("none");
        Xrm.Page.getAttribute("value3").setRequiredLevel("none");
       }
     else  {    
        Xrm.Page.getAttribute("value1").setValue("");
        Xrm.Page.getAttribute("value2").setRequiredLevel("none");
        Xrm.Page.getAttribute("value3").setRequiredL

    Friday, October 10, 2014 4:04 PM

All replies

  • Hi Everyone,

    Can anyone assist me with the below javascript code, I keep getting errors onchange event (see below image). I'm no expert on JS but I have enough knowledge to get by, but this Is causing me problems. It only errors when I select value 1 "Yes".

    "Error: Unable to get property 'setvalue' of undefined or null reference"

    Any assistance would be greatly appreciated.

    Regards
    Paul

    function allowance_test()
    {
        if(Xrm.Page.getAttribute("value1").getSelectedOption() != null){
        if(Xrm.Page.getAttribute("value1").getSelectedOption().text =="Yes")

       {
        Xrm.Page.getAttribute("value2").setRequiredLevel("required");
        Xrm.Page.getAttribute("value2").setRequiredLevel("required");
       }
     if(Xrm.Page.getAttribute("value1").getSelectedOption().text =="No")

       {
        Xrm.Page.getAttribute("value3").setRequiredLevel("none");
        Xrm.Page.getAttribute("value3").setRequiredLevel("none");
       }
     else  {    
        Xrm.Page.getAttribute("value1").setValue("");
        Xrm.Page.getAttribute("value2").setRequiredLevel("none");
      }

    }

    }

    Friday, October 10, 2014 4:11 PM
  • Hi ,

    İnstead of using this code Xrm.Page.getAttribute("value1").setValue("");

    try using Xrm.Page.getAttribute("value1").setValue(null);


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın http://crmpolataydin.wordpress.com

    Friday, October 10, 2014 4:37 PM
  • Friday, October 10, 2014 4:50 PM
  • Hi,

    Please make sure field name is correct and field is added on form.

    you can always check if field is available on form using

    if(Xrm.Page.getAttribute("value1")!=null)

    If you want to clear field value use

    if(Xrm.Page.getAttribute("value1")!=null)

    {

     Xrm.Page.getAttribute("value1").setValue(null);

    }

    Sunday, October 12, 2014 10:57 AM