1

When I want to display between two subject lines it works fine but when I need to add a fall back if there is no first name it stops working.

This works to display a subject line depending on what state is in the data:

 <!--%%[
var @FirstName, @subjectline, @salutation, 

set @Email = Lowercase([Email]) 
set @FirstName = ProperCase([FirstName])
set @State = [State]

       if @State == "NSW" then
  set @subjectline = Concat(@firstname,", have you reviewed your strata proposal?")
elseif @State == "VIC" or @State == "QLD" then
  set @subjectline= Concat(@firstname,", have you reviewed your body corporate proposal")
endif

]%%
 -->

This isn't working:

if @State == "NSW" then
    if Empty(@FirstName) or IsNull(@FirstName) then
        set @subjectline = "Have you reviewed your strata proposal?"
    else
        set @subjectline = Concat(@FirstName,", have you reviewed your strata proposal?")
         endif

 if @State == "VIC" or @State == "QLD" then
    if Empty(@FirstName) or IsNull(@FirstName) then
         set @subjectline = "Have you reviewed your body corporate proposal?"
    else
         set @subjectline = Concat(@FirstName,", Have you reviewed your body corporate proposal?")
    endif
3

You have opened both @State if statements twice, but only closed them once.

I would simplify your code to control expression evaluation using parentheses. Here's some working code:

%%[
var @FirstName, @subjectline, @salutation

set @Email = Lowercase(Email) 
set @FirstName = ProperCase(FirstName)
set @State = State

if @State == "NSW" and (Empty(@FirstName) or IsNull(@FirstName)) then
   set @subjectline = "Have you reviewed your strata proposal?"
elseif @State == "NSW" then
   set @subjectline = Concat(@FirstName,", have you reviewed your strata proposal?")
elseif (@State == "VIC" or @State == "QLD") and (Empty(@FirstName) or IsNull(@FirstName)) then
   set @subjectline = "Have you reviewed your body corporate proposal?"
elseif (@State == "VIC" or @State == "QLD") then
   set @subjectline = Concat(@FirstName,", Have you reviewed your body corporate proposal?")
else
   RaiseError('empty subject line')
endif

]%%

Note that you only need to wrap attributes in [square brackets] if the attribute name contains a space or hyphen character.

7
  • That's good to hear. Please could you accept my answer for the benefit of others, and (optionally) feel free to upvote it, if you found it to be helpful. Jul 24 '18 at 6:05
  • Hi - the error went away and it appeared to be working but I am noticing now that it is only pulling in @state "VIC" and "QLD". "NSW" is not pulling in at all. Jul 24 '18 at 6:28
  • For @State "NSW" it is pulling in the "VIC" and "QLD" subject line Jul 24 '18 at 6:44
  • Hello @Michaelsyd, I've spotted an issue with my conditional logic which would be causing the behaviour you report. I've updated my answer with code that should work. Jul 24 '18 at 7:08
  • 1
    IsNull is actually redundant here, as when using the Empty function, If the expression evaluates as null or empty, the function will output true. IsNull effectively does the same thing, but will only work with DE fields. Jul 31 '18 at 16:45

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.