0

I want to create a dynamic subject line that has a fallback if no firstname is present.

Here is the approach I would normally take - %%[IF NOT EMPTY(First_Name) AND First_Name != "SIR/MADAM" AND First_Name != "Customer" THEN]%%%%=ProperCase(First_Name)=%%, lowercase subject%%[ELSE]%%Uppercase subject%%[ENDIF]%%

However in this instance, I want to create a variable in my code, and simply pull in this variable via SFMC.

The below approach throws me the error 'IF Not Closed An IF statement is not closed with the required ENDIF statement'

Code

     set @subject = ""
     IF Offer_Flag == "1" THEN
        set @subject = "Non-dynamic Subject"
     ELSEIF Offer_Flag == "2" AND NOT EMPTY(First_Name) AND First_Name != "SIR/MADAM" AND First_Name != "Customer" THEN
        set @subject = Concat(ProperCase(First_Name), ", here’s *15% off*!"
     ELSE
        set @subject = "Here’s *15% off*!"
     ENDIF

SFMC

%%=V(@subjectLine)=%%

1
  • edited my answer based on your new code. – Gortonington Aug 15 '20 at 13:43
1

You can still use most of what you had in your first example:

%%[
IF NOT EMPTY(First_Name) AND First_Name != "SIR/MADAM" AND First_Name != "Customer" THEN
  Set @subject = Concat(ProperCase(First_Name), ", this is your email" 
ELSE
  Set @subject = "This is your email"
Endif
]%%%

Can also use inline if:

Set @subject = CONCAT(IIF(NOT EMPTY(First_Name) AND First_Name != "SIR/MADAM" AND First_Name != "Customer", CONCAT(ProperCase(First_Name),","), "")"this is your email")

EDIT Based on comment/question:

IF Offer_Flag == "1" THEN 
  set @subject = "Non-dynamic Subject" 
ELSEIF Offer_Flag == "2" AND NOT EMPTY(First_Name) AND First_Name != "SIR/MADAM" AND First_Name != "Customer" THEN 
  set @subject = Concat(ProperCase(First_Name), ", here’s *15% off*!")
ELSE 
  set @subject = "Here’s *15% off*!" 
ENDIF

You were missing the closing ) on your CONCAT().

2
  • Thanks a lot, the helps a lot, however in my case I'm switching the subject line based on a flag in the DE, only the 2 second flag is using first name personalisation. I've edited my question to reflect this. – Jordan Miguel Aug 15 '20 at 13:17
  • 1
    That's great, thanks for the help on this. Makes a lot of sense and I'm glad I can do this inline! – Jordan Miguel Aug 15 '20 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.