locked
Lookup throwing an error RRS feed

  • Question

  • I have a user name lookup  field. if the form is filled with the lookup its not throwing an error, but if its empty it is thrwoing an error saying "crmForm.all.new.DataValue.0" null or not an object.

    when i create a form its does not have the lookup value and i dont want this to throw an error when its empty

    what could be the fix?

    Tuesday, May 10, 2011 2:28 PM

Answers

All replies

  • On you onload code use

     if (crmForm.all.new.DataValue != null)

    {

    //Do somrthing

    }

    Also note that crmForm.all.new.DataValue[0].name will give you the name of lookup and crmForm.all.new.DataValue[0].id will give you id of lookup.

     


    Regards Faisal
    Tuesday, May 10, 2011 2:41 PM
  • Faisal is right, as long as this is CRM 4.0 and isn't CRM 2011, if it was you are using the wrong syntax entirely.
    Jamie Miley
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, May 10, 2011 2:55 PM
    Moderator
  • its crm 4.0

    if (crmForm.all.newsecondpointofcontactid.DataValue != null))

    {

    }

     

    is this what i have to give

     

    but what if its null ?

    Tuesday, May 10, 2011 3:13 PM
  • debugger;

    var poc1 = crmForm.all.newsecondpointofcontactid.DataValue[0].id.replace('{', '').replace('}', '');
    var alternatepointofcontact = poc1.toLowerCase();

    if (crmForm.all.newsecondpointofcontactid.DataValue[0].id  != null)

    {

    }


    if (crmForm.all.newsecondpointofcontactid.DataValue[0].id  ==  null)

    {

    }

     

    is this correct?

    Tuesday, May 10, 2011 3:23 PM
  • Should be pretty close, the debugger; option you are trying should also let you see what's in those form elements if you add a watch.

    You need to make sure enable debugging in IE also to make that work.

    Here is a post that covers (in the second half of the post).

    http://mileyja.blogspot.com/2011/03/microsoft-dynamics-crm-2011-parsing.html


    Jamie Miley
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, May 10, 2011 3:39 PM
    Moderator
  • You have to test for null BEFORE you attempt to use DataValue:

    if (crmForm.all.newsecondpointofcontactid.DataValue != null) {
      var poc1 = crmForm.all.newsecondpointofcontactid.DataValue[0].id.replace('{', '').replace('}', '');
      var alternatepointofcontact = poc1.toLowerCase();
    }
    
    
    If DataValue is null (because no lookup has been assigned), there is nothing in it to retrieve/manipulate.


    --pogo (pat)
    Tuesday, May 10, 2011 8:03 PM
  • Thanks.
    Thursday, May 12, 2011 3:55 PM
  • You should mark the replies that formed the answer as answers then. :)
    Jamie Miley
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    • Marked as answer by CRMAG Friday, May 13, 2011 4:59 PM
    Thursday, May 12, 2011 3:56 PM
    Moderator