locked
unable to get value of the property '0' object is null or undefined JAVA SCRIPT ERROR RRS feed

  • Question

  • Hi all,

               Need help if i use Code like Below means its working fine but if i change like Step 2 means Getting Error "unable to get value of the property '0' object is null or undefined "

     Please alter this code

    STEP 1 : Working Code

    function new_financeidid_onchange()
    {
    if(crmForm.all.new_financeidid.DataValue != null)
    {
    var new_financeidid = document.getElementById( "new_financeidid");
    var lookupItems = new_financeidid.items[0].values;
    Xrm.Page.getAttribute("new_grossmargin").getValue()=lookupItems[2].value;
    }}

    STEP 2 : Not workling

    function new_financeidid_onchange()
    {
    if(Xrm.Page.getAttribute("new_financeidid").getValue() != null)

    alert('1');
    var new_financeidid = document.getElementById( "new_financeidid");
    var lookupItems = new_financeidid.items[0].values;              // Getting error here
    alert('2');
    Xrm.Page.getAttribute("new_grossmargin").getValue()=lookupItems[2].value;
    alert('3');

    }

    }

    Monday, April 8, 2013 10:39 AM

Answers

  • Step 2 should work for you if you use this:

    var lookupItem = new Array(); 
     lookupItem = Xrm.Page.getAttribute(yourAttributeSchemaName).getValue();
     
     if (lookupItem[0] != null) 
     {
     
       var name = lookupItem[0].name; 
       var guid = lookupItem[0].id; 
       var entType=  lookupItem[0].entityType;
     
      }


    If the answer helped you, remember to mark it as answer.
    My Weblog -- My Website -- My Facebook

    Monday, April 8, 2013 11:22 AM
    Moderator

All replies

  • Step 2 should work for you if you use this:

    var lookupItem = new Array(); 
     lookupItem = Xrm.Page.getAttribute(yourAttributeSchemaName).getValue();
     
     if (lookupItem[0] != null) 
     {
     
       var name = lookupItem[0].name; 
       var guid = lookupItem[0].id; 
       var entType=  lookupItem[0].entityType;
     
      }


    If the answer helped you, remember to mark it as answer.
    My Weblog -- My Website -- My Facebook

    Monday, April 8, 2013 11:22 AM
    Moderator
  • Payman,

           i Tried below code it shows some other Error

    function new_financeidid_onchange()
    {
    var lookupItem = new Array();
     lookupItem = Xrm.Page.getAttribute("new_financeidid").getValue();
    alert(lookupItem );
     
     if (lookupItem[0] != null)
     {
     var name = lookupItem[0].name;  var guid = lookupItem[0].id;   var entType=  lookupItem[0].entityType;
    Xrm.Page.getAttribute("new_grossmargin").setValue(lookupItem[2].value); }

    Its shows error Like unable to get value of the property 'value' object is null or undefined..

    So i alter like this

    function new_financeidid_onchange()
    {
    var lookupItem = new Array();
    lookupItem = Xrm.Page.getAttribute("new_financeidid").getValue();
    alert(lookupItem );

    if (lookupItem[0] != null)
    {
    var name = lookupItem[0].name;  var guid = lookupItem[0].id;   var entType=  lookupItem[0].entityType;
    Xrm.Page.getAttribute("new_grossmargin").setValue(lookupItem[2]); }

    but am getting Error as cannot assign to a function result


    Monday, April 8, 2013 11:54 AM
  • Hello,

    have a look at  the arraycounter [2]  in the line  .... Xrm.Page.getAttribute("new_grossmargin").setValue(lookupItem[2].value);  ....

    I think this arrayelement [2] is null or not initalized. I think, the array LookupItem is filled only for the arrayelement =  [0]


    Herzliche Grüße / Best regards Markus Müller If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Monday, April 8, 2013 1:14 PM