1

I'm modifying an email template to check if a state value is true or not, if it is, display a specific value, otherwise, display a default message.

My code is as follows:

%%[
    IF @Ship_State == "CO" THEN
        SET @TaxDisplay = "Not collected"
    ELSEIF @Ship_State == "LA" THEN
        SET @TaxDisplay = "Not collected"
    ELSEIF @Ship_State == "VT" THEN
        SET @TaxDisplay = "Not collected"
    ELSE
        SET @TaxDisplay = Format([OrderTax],"$#,#.00")

]%%
%%[ENDIF]%%

%%=v(@TaxDisplay)=%%

I've checked the data of @Ship_State, and it is always a two letter abbreviation with capital letters. So it's not a legitimate data mismatch issue.

When testing the email, seemingly half the time when ship state is CO, LA, or VT it either correctly outputs "Not collected" or it doesn't when it should.

1
  • AMPScript's not flakey in this area. Long-winded, but your code looks good based on what you've posted. I'd recheck the data you have to make sure that you don't need to reconsider your evaluations... Do you have white space or unprintables in your data? Is there a common thread to where you see the script going wrong - is the final else catching stuff you're expecting to be caught by the previous clauses? Is your issue further back where you set @Ship_State?
    – Macca
    Commented Jun 15, 2017 at 10:30

1 Answer 1

0

I think the code could be written better (i.e making the logic tighter).

Try this:

%%[
    IF ( @Ship_State == "CO" OR @Ship_State == "LA" OR  @Ship_State == "VT" ) THEN
        SET @TaxDisplay = "Not collected"
    ELSE
        SET @TaxDisplay = Format([OrderTax],"$#,#.00")
    ENDIF   
]%%

%%=v(@TaxDisplay)=%%
1
  • Can you add a bit of explanation?
    – Adrian Larson
    Commented Jun 14, 2017 at 22:21

You must log in to answer this question.

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