locked
CRM 2011: Object Expected Error RRS feed

  • Question

  • Hi, I'm a Javascript newbie, and am trying to do a simple script in CRM 2011. I can't stop getting the ever-useful "object expected" error, so am hoping someone can tell me what I'm doing wrong here?

    The function is below, triggers on the onChange event of the customertypecode field.

    function GPAcc() {

            var val1 = Xrm.Page.getAttribute("customertypecode").getSelectedOption().text;

            if(val1 == "Customer") {
                   Xrm.Page.getAttribute("accountnumber").setRequiredLevel("required");
            } Else {
                      Xrm.Page.getAttribute("accountnumber").setRequiredLevel("none");
            }
     }

    Thursday, July 24, 2014 10:18 PM

Answers

  • try with getText instead of getSelectedOption().text, the reason is that getText works also when the optionset is empty.

    also you need to write "else", not "Else"

    gunction GPAcc() {
    
            var val1 = Xrm.Page.getAttribute("customertypecode").getText();
    
            if(val1 == "Customer") {
                   Xrm.Page.getAttribute("accountnumber").setRequiredLevel("required");
            } else {
                      Xrm.Page.getAttribute("accountnumber").setRequiredLevel("none");
            }
     }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Friday, July 25, 2014 12:32 AM
    • Marked as answer by Capnjimnz Friday, July 25, 2014 1:48 AM
    Friday, July 25, 2014 12:32 AM

All replies

  • try with getText instead of getSelectedOption().text, the reason is that getText works also when the optionset is empty.

    also you need to write "else", not "Else"

    gunction GPAcc() {
    
            var val1 = Xrm.Page.getAttribute("customertypecode").getText();
    
            if(val1 == "Customer") {
                   Xrm.Page.getAttribute("accountnumber").setRequiredLevel("required");
            } else {
                      Xrm.Page.getAttribute("accountnumber").setRequiredLevel("none");
            }
     }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Friday, July 25, 2014 12:32 AM
    • Marked as answer by Capnjimnz Friday, July 25, 2014 1:48 AM
    Friday, July 25, 2014 12:32 AM
  • That did it! Thanks very much for your help.
    Friday, July 25, 2014 1:48 AM