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.

  • 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 Jun 15 '17 at 10:30
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)=%%
| improve this answer | |

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.