locked
Javascript to set field required - error RRS feed

  • Question

  • I have an onChange jscript on the opportunity form that is not working. When I choose combinations of that would set field required nothing happens, when i choose requesttype to be blank i receive error debugging: script5007: unable to get value of the property 'text'; object is null or undefined. 

    function setRequire() {

        var type = Xrm.Page.getAttribute('new_opportunitytype').getSelectedOption().text;
        var requesttype = Xrm.Page.getAttribute('orbus_requesttype').getSelectedOption().text;
        if (type == "Standard / Stock Items" && requesttype == "Rendering Only") 
      {

            Xrm.Page.getAttribute("orbus_endclientname").setRequiredLevel("required");
        }

        if (type == "Custom " && requesttype != null) 
     {
            Xrm.Page.getAttribute("orbus_endclientname").setRequiredLevel("required");

        }
        else if (type == "Rental " && requesttype != null) 
     {
            Xrm.Page.getAttribute("orbus_endclientname").setRequiredLevel("required");

        }
        else if (type == "Systems" && requesttype != null) 
     {
            Xrm.Page.getAttribute("orbus_endclientname").setRequiredLevel("required");

        }
           


     }

    Monday, December 8, 2014 4:09 PM

Answers

  • Hi,

    getSelectedOption() will return null if there is no value selected.So getSelectedOption().text will throw error.

    To get the text of selected option,it is better to use the below code : 

    Xrm.Page.getAttribute("fieldname").getText();

    Thanks,
    Seban
    • Marked as answer by Nicole_CRM Monday, December 8, 2014 4:42 PM
    • Edited by Seban Mathews Monday, December 8, 2014 4:45 PM
    Monday, December 8, 2014 4:33 PM