I have some ampscript in my emails that sets a variable to either a string or whatever value is in the name of the email, and the logic uses the fields LastLoggedInDate and LastEmailOpenedDate. The LastEmailOpenedDate field won't exist in the sending data extension if the email is not a newsletter. I've tried using an IF statement that returns false if the LastEmailOpenedDate is null, but apparently a field being null and it just not existing are different things, and I get a validation error when previewing the email.

I've also tried nesting that IF statement inside of another one that checks if the email is a newsletter before even looking at the LastEmailOpenedDate field, but I still get the same error. Ampscript must be validating all the code, whether or not the IF statements return true.

Is there any way I can get ampscript to truly ignore that line of code when a condition is true? Otherwise I have to manually remove that line of script every time I copy a newsletter to use in another campaign, and if I or someone else on my team forgets, the job fails.

The code and the error I'm getting are here:

IF @Campaign == "Newsletter" THEN
  IF (LastLoggedInDate < DateAdd(Now(), '-340','D') AND (LastEmailOpenedDate < DateAdd(Now(), '-155','D') OR IsNull(LastEmailOpenedDate))) THEN 
    SET @Audience = "Winback" 
    ELSE SET @Audience = Field(Row(BuildRowSetFromString(EmailName_, '_'), 4), 1) 

Script Expression: LastEmailOpenedDate JobID: 0 An unrecognized expression appears in a script block. Script Expression: LastEmailOpenedDate JobID: 0
Invalid Content:
IF (LastLoggedInDate

1 Answer 1


You should use AttributeValue() function, to grab the value of LastLoggedInDate and LastEmailOpenedDate from the data extension:

SET @LastLoggedInDate = AttributeValue("LastLoggedInDate")
SET @LastEmailOpenedDate = AttributeValue("LastEmailOpenedDate")
IF @Campaign == "Newsletter" THEN
  IF (@LastLoggedInDate < DateAdd(Now(), '-340','D') 
  AND (@LastEmailOpenedDate < DateAdd(Now(), '-155','D') 
  OR IsNull(@LastEmailOpenedDate))) THEN 
    SET @Audience = "Winback"
    SET @Audience = Field(Row(BuildRowSetFromString(EmailName_, '_'), 4), 1) 
  • 1
    To add more context, if you are looking to grab an attribute that does not exist inside of the sendable data it will throw an exception due to the processor assuming that it is a necessary part of your code - but by using AttributeValue and assigning it to an AMPScript variable, you can return a 'null' or 'empty' value if it does not exist and then handle that exception on your own. Commented Mar 31, 2021 at 19:32
  • I still don't understand AttributeValue to its full potential. Giving me Headaches... like shown here Commented Apr 1, 2021 at 7:40

You must log in to answer this question.

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