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) ENDIF ENDIF
Script Expression: LastEmailOpenedDate JobID: 0 An unrecognized expression appears in a script block. Script Expression: LastEmailOpenedDate JobID: 0