Stefan Cameron on Forms
Building intelligent forms using Adobe LiveCycle Designer

Is that Field Empty?

As a form designer, you can be almost certain that there will be a time when you’ll need to check a field to see whether its value is empty (whether the form filler has specified a value).

For longest time, I had been doing it like this in JavaScript:

if (theField.rawValue == null || theField.rawValue.length == 0)
  // field is empty
  // field has been filled

That served me quite well until yesterday when I found myself needing to do the same, but this time in FormCalc. Theoretically, the following should’ve worked:

if (theField == null | theField == "") then
  // field is empty
  // field has been filled

But for some reason, the FormCalc interpreter was giving me a hard time with the null keyword (maybe it’s because I don’t use it very often and it was upset at me, I don’t know — if you’re a developer, you’ll understand that sometimes, code can have feelings and a mind of its own 😉 ) so was forced to try and find some other way to check if a field’s value is null in FormCalc and I found one:


The isNull property (of the XFA Scripting Model’s node object) “indicates whether the current data value is the null value”, as stated on page 422 of the Adobe XML Form Object Model Reference (located in the XML section).

This means that the following JavaScript expression checks whether a field’s value is empty:

(theField.isNull || theField.rawValue.length == 0)

And in FormCalc:

(theField.isNull | theField == "")

Posted by Stefan Cameron on May 19th, 2006
Filed under Scripting
Both comments and pings are currently closed.

8 Responses to “Is that Field Empty?”

  1. Karen on December 29th, 2006

    I have also used HasValue(theField) for FormCalc

  2. Dewey Vozel on April 3rd, 2008

    I had a problem with a script that I wrote recently. I typically check (theField.isNull || theField.rawValue.length == 0) but for some reason with this text field (that is exactly like all of the other text fields settings-wise) I was getting an error thrown into my try/catch block that theField doesn’t have a property called rawValue when it was empty. Now, if I put a string into the field and deleted it then it would succeed. If I never touched the field it would fail. This is in LiveCycle Designer 7.1

    So my solution in javascript was:

    if ((theField.isNull) || (theField.rawValue == undefined)) { … }

    I tested a couple of different versions out and this one seems to be the most reliable.

  3. Khalid on October 29th, 2008

    Hi I needed a help, I got fields:
    Name (Text Field)
    Total (Number , sum of other fields)
    GrandTotal ( Number calculated, Total – Commission)

    Now what I want is, if Name is Blank then Commission should be 0, if we enter any thing in field name then Comission should be 15% of total.

    Your help will be appreciated.

  4. Stefan Cameron on November 4th, 2008


    You could use a Calculate script on the Commission field:

    if (Name.rawValue != null && Name.rawValue.length > 0)
        this.rawValue = 0.15 * Total.rawValue;
        this.rawValue = 0;
  5. Mike on February 6th, 2009

    What is the syntax for is NOT Null?

  6. Stefan Cameron on February 13th, 2009


    To check if a value isn’t null, you can do this (in JavaScript)

    if (!(theField.isNull || theField.rawValue.length == 0))

    or this (in FormCalc)

    if (not (theField.isNull | theField == ""))
  7. Todd on July 1st, 2010

    Hello Stefan,

    You have helped me with some other items in the past I hope you can help again, you do great work.

    I have a drop down field that fills in information in an email based on the item they select. I have 2 specific items that if they are selected will add a statement stating they need to use a specific part number to order more of that part. I have it set up also if they select a yes or no answer the email will either read no problems were found, select “Yes” all the information is pulled and populate in to the email.

    To my point, if they select No the 2 specific items show up on the email as Null, is there a way so that the Null word does not appear, I am looking to have absolutely nothing appear if those fields are blank.

    Thank You for your help

  8. Stefan Cameron on July 12th, 2010



    Can you post the script in question? If “null” is showing-up in the text, it’s usually because you’re including the value of some variable in a string and that variable is null. There must be something going wrong when the selected answer is “No” vs “Yes”.