0

I am trying to write a piece of IF clauses based on some data and depending if I have a match in the Index then i will have a code and another piece of code if there is no match. I will also need to consider the unsubscribe statuses.

the first IF works correctly and displays the flags correctly but I have issues when I put the secondary IF in the logic.

Below is a strip version of my code:

  %%[

SET @special_date_day="01"
SET @special_date_month="JANUARY"
SET @special_date_year="****"


SET @asterix="*"


SET @email_status_updates = "unsubscribed"
SET @email_unsub_reason='I don't like the brand'

set @today = Now(1) /* valid */
SET @dateSubmitted = DateAdd(@today, 6, "H")



if IndexOf(@special_date_year,@asterix) > 0 then 

SET @Flag="Este asterix"

IF (@email_status_updates == "unsubscribed" and @email_unsub_reason != "Other") THEN
SET @Insert="I instert for the unsubscribe brach"
ELSE 
ENDIF 


else

SET @Flag="nu este asterix"

IF (@email_status_updates == "unsubscribed" and @email_unsub_reason != "Other") THEN
SET @Insert="I insert for the non unsubscribe branch"
ELSE 
ENDIF 


ENDIF
]%%


<br> 
<br>Cu insert and asterix in the if first <br>
year: %%=v(@special_date_year)=%%<br>
noul Flag: %%=v(@Flag)=%%<br>
Insert: %%=v(@Insert)=%%<br>

When I do a send preview it only shows the year variable; the other two are null.

What did I miss in order to correct this?

Giulietta

2
  • Have you tried removing the "ELSE" statement after "SET @Insert" lines? You don't need to set these ELSE statements. Also "else" should be in UPPERCASE. Jan 28, 2020 at 12:19
  • 3
    AMPscript is case-insensitive. Jan 28, 2020 at 12:41

2 Answers 2

2

You have two problems in your code:

Problem #1: I think there is a misunderstanding of the IF/ELSE statments, hence, you have some unecessary ELSE's in your code.

Problem #2: You need to use double quote instead of simple quote when setting @email_unsub_reason.

Your code should be:

%%[

SET @special_date_day="01"
SET @special_date_month="JANUARY"
SET @special_date_year="****"


SET @asterix="*"


SET @email_status_updates = "unsubscribed"
SET @email_unsub_reason="I don't like the brand"

set @today = Now(1) /* valid */
SET @dateSubmitted = DateAdd(@today, 6, "H")



IF IndexOf(@special_date_year,@asterix) > 0 then 

    SET @Flag="Este asterix"

    IF (@email_status_updates == "unsubscribed" and @email_unsub_reason != "Other") THEN
    SET @Insert="I instert for the unsubscribe brach"
    ENDIF 


ELSE

    SET @Flag="nu este asterix"

    IF (@email_status_updates == "unsubscribed" and @email_unsub_reason != "Other") THEN
    SET @Insert="I insert for the non unsubscribe branch" 
    ENDIF 


ENDIF
]%%


<br> 
<br>Cu insert and asterix in the if first <br>
year: %%=v(@special_date_year)=%%<br>
noul Flag: %%=v(@Flag)=%%<br>
Insert: %%=v(@Insert)=%%<br>
3

You should use double-quotes surrounding the string in your set-statement for the @email_unsub_reason -- since the value contains single quotes.

I'd get rid of the empty ELSE's also.

You might try adding output/concat combos for debugging before any conditionals.

%%[

SET @special_date_day="01"
SET @special_date_month="JANUARY"
SET @special_date_year = "****"
SET @asterix = "*"
SET @email_status_updates = "unsubscribed"
SET @email_unsub_reason = "I don't like the brand"
set @today = Now(1) /* valid */
SET @dateSubmitted = DateAdd(@today, 6, "H")

output(concat("<br>index: ", IndexOf(@special_date_year, @asterix)))

if IndexOf(@special_date_year, @asterix) > 0 then 

    SET @Flag = "Este asterix"

    IF (@email_status_updates == "unsubscribed" and @email_unsub_reason != "Other") THEN
        SET @Insert = "I insert for the unsubscribe branch"
    ENDIF 

else

    SET @Flag = "nu este asterix"

    IF (@email_status_updates == "unsubscribed" and @email_unsub_reason != "Other") THEN
        SET @Insert = "I insert for the non-unsubscribe branch"
    ENDIF 

ENDIF
]%%
<br><br>Cu insert and asterix in the if first 
<br>year: %%=v(@special_date_year)=%%
<br>noul Flag: %%=v(@Flag)=%%
<br>Insert: %%=v(@Insert)=%%

You must log in to answer this question.

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