Getting 'null' is null or not an object RRS feed

  • Question

  • Hello, I am very new to MS CRM 4.0.  I am creating some scripting for three fields for zip codes.  The first field is the first 5 digits.  The next field is the +4 for the zip code. The last field is taking the other two and combining them (99999-9999) depending on what is their values. 

    Here is the code for the first field:


    var control1 = crmForm.all.new_address1zip;
    var zip = control1.DataValue;
    var control2 = crmForm.all.new_address1zip4;
    var zip4 = control2.DataValue;
    var control3 = crmForm.all.address1_postalcode;
    var zipcode = control3.DataValue;

    //Make sure that the Zip is 5 digits
    var match5 = zip.match(/^(\d{5})$/);
    if (match5 == null)
        alert('Invalid zip code. Must be 5 digits.');
        msg = "does not appear to be valid";
        control1.DataValue = null;
        event.returnValue = false;

    //Take the Zip and the Zip+4 and combine to the ZipCode
    var match4 = zip4.match(/^(\d{4})$/);
    if (match4 == null)
        zipcode = zip;
        zipcode = zip + "-" + zip4;
    control3.DataValue = zipcode;

    When I enter a value into the first field, I get the error.  There is no value in the +4 field.  I am thinking that this is the issue.  Besides the "match" what are some other checks that I can use?  Where can I get this information.



    Eddi Rae

    Thursday, May 6, 2010 1:45 PM


  • I found my issue.  I need to check to see if there is a value in the zip4 before I actually try to do the match on it.
    • Proposed as answer by ckeller Thursday, May 6, 2010 7:12 PM
    • Marked as answer by Jim Glass Jr Monday, May 10, 2010 3:10 PM
    Thursday, May 6, 2010 2:37 PM