locked
CRM OPTIONSET THROWING ERROR URGENT!! RRS feed

  • Question

  • I have a  option set having

    Small Business as value 1

    Lenders as value 2

    My code is

    function Form_onload()
    {


    if (Xrm.Page.getAttribute("new_counselingfor").getText() == "Lenders")

    {
       alert("Lenders");
    }

    if (Xrm.Page.getAttribute("new_counselingfor").getValue() == 1)

    {
       alert("sb");
    }

     but this is throwing me an error

    There was an error with this  fields customized event

    Field : Window

    Event: onload

    error: unable to get value of the proprty "getText:" oject is null or undefined

    Thursday, August 9, 2012 3:43 PM

Answers

  • Are you sure your field name uses the "new" prefix and not a custom one that you defined? Or is there a typo in "new_counselingfor" or is the field name something else?

    I can reproduce this error if I have an incorrect field name on the line that references 'getValue()'


    Jason Lattimer


    Thursday, August 9, 2012 5:42 PM
    Moderator

All replies

  • Try this:

    var YourValue = Xrm.Page.data.entity.attributes.get("yourField").getSelectedOption().text;
    

    Jason Lattimer

    Thursday, August 9, 2012 3:54 PM
    Moderator
  • ok changed code to

    function Form_onload()
    {

     
    var YourValue = Xrm.Page.data.entity.attributes.get("new_counselingfor").getSelectedOption().text;


    alert(YourValue);

    }

    this now throw an error saying

    unable to get value of the proprty "getSelectedOption" oject is null or undefined

    Thursday, August 9, 2012 4:06 PM
  • When the form loads - is the option set to a value by default or is it empty? If it is empty when the form loads you'll see an error because there is no 'selected option'.

    Maybe try testing your code on the OnChange event for that option set. 


    Jason Lattimer

    Thursday, August 9, 2012 4:34 PM
    Moderator
  • Hi,

    Try this

    if(Xrm.Page.getAttribute("new_counselingfor").getValue()!=null)

    {

    var YourValue=Xrm.Page.getAttribute("new_counselingfor").getSelectedOption().text;

    alert(YourValue);

    }



    Conatact Me
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, August 9, 2012 4:56 PM
    Moderator
  • so this time I try this code and I have set "small Business" as default in my option set

    Still getting error

    unable to get value of the proprty "getValue" oject is null or undefined

    its simple but still frustrating can someone help me out here

    function Form_onload()
    {

    if(Xrm.Page.getAttribute("new_counselingfor").getValue() != null)
     
    {
     
    var YourValue=Xrm.Page.getAttribute("new_counselingfor").getSelectedOption().text;
     
    alert(YourValue);
     
    }

     

    }

    Thursday, August 9, 2012 5:31 PM
  • Are you sure your field name uses the "new" prefix and not a custom one that you defined? Or is there a typo in "new_counselingfor" or is the field name something else?

    I can reproduce this error if I have an incorrect field name on the line that references 'getValue()'


    Jason Lattimer


    Thursday, August 9, 2012 5:42 PM
    Moderator
  • Jason,

    Indeed u caught me right, it was a spellingmistake, now it works.

    Toooo bad I need to clear my head.

    Thanks A LOT Jason and Mahender.

    AG

    Thursday, August 9, 2012 6:01 PM