-1

I have a very simple JS script that is embedded into an email. The goal is to autopopulate the salutation of the email and is as follows.

if (Contact.Field("firstname") == "NULL") {
    document.write(Contact.Field("custname"));
} else if (Contact.Field("firstname") == "") {
    document.write(Contact.Field("lastname")"Household");
} 

The problem I'm running into is that the script will still autopopulate the NULL value in the email instead of switching to the "custname" field when it runs. I'm sure this is due to user error, but if anyone could help steer me in the right direction I would greatly appreciate it. Thanks!

J Zirkle
  • 23
  • 2

1 Answers1

0

You have used "NULL" in the if statement, where you should have used null (without quotes, and in lowercase letters.) on it's own, like this:

if (Contact.Field("firstname") == null) {
    document.write(Contact.Field("custname"));
} else if (Contact.Field("firstname") == "") {
    document.write(Contact.Field("lastname")"Household");
} 

Using "NULL" would check if the text in Contact.Field("custname") was the string "NULL", rather than checking if it has no content.

As to whether to use == or ===, you can find an answer here: Which equals operator (== vs ===) should be used in JavaScript comparisons?

Daniel Beck
  • 20,653
  • 5
  • 38
  • 53
James Douglas
  • 3,328
  • 2
  • 22
  • 43