0

Right now, I have this AMPscript that displays first name of the subscriber from the data extension since I am sending email to data extension as audience.

%%[
var @fname
set @fname = [First-Name]
]%%

Dear %%[IF not empty(@fname) THEN]%%%%=v(@fname)=%%%%[ELSE]%%Customer%%[ENDIF]%%

But, when I try to add more columns from the same data extension so that I can display value from address, title etc I get error in my AMPscript?

Can anyone please clarify if my ampscript is correct? if no, how can i correct it?

This is what I got so far:

%%[
var @fname, @decolumn_2, @decolumn_3
set @fname = [First-Name]
set @decolumn_2 = [DE-Column-2]
set @decolumn_3 = [DE-Column-3]
]%%

Dear %%[IF not empty(@fname) THEN]%%%%=v(@fname)=%%%%[ELSE]%%Customer%%[ENDIF]%%


Displaying other information below:

%%=v(@decolumn_2)=%% | %%=v(@decolumn_3)=%%

1 Answer 1

2

The issue could stem from if any of those columns are empty or null values. AMPscript can sometimes have issues with variables being set to null and throw errors.

To better handle null or empty values, I would recommend using the AttributeValue() function for setting your variables.

Example:

%%[

  VAR @fname, @decolumn_2, @decolumn_3

  SET @fname = AttributeValue("First-Name")
  SET @decolumn_2 = AttributeValue("DE-Column-2")
  SET @decolumn_3 = AttributeValue("DE-Column-3")

]%%

  Dear %%[IF not empty(@fname) THEN]%%%%=v(@fname)=%%%%[ELSE]%%Customer%%[ENDIF]%%


  Displaying other information below:

  %%=v(@decolumn_2)=%% | %%=v(@decolumn_3)=%%
2
  • Thank you. Is this another way to solve issue because this will handle NULL value too? OR attribute is a safer way to go about it? %%[IF not empty(@decolumn_2) THEN]%%%%=v(@decolumn_2)=%%%%[ELSE]%%DE_Default_Value%%[ENDIF]%%
    – kuml
    Jul 17, 2017 at 12:53
  • It is the SETTING of the variable part that has issues with NULL, not the conditional statements. AttributeValue is usually best practice when setting variables as it is the most flexible. Jul 17, 2017 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .