Please forgive my beginner level understanding here, I've been thrust into modifying an email that hasn't been touched in a few years, and I've never used AMPScript before. I'll try to keep this concise, but some context is needed in order to understand the problem.
For an order-status email, we are displaying a tax value, and this tax value needs to be changed depending on one of a few conditions. Those are:
- Single product, with a "flagged state", then Tax = "Not collected".
- Single Product, with non-flagged state and non-tax state, then Tax = $0.00
- Single Product, with non-flagged state and TAX state, then Tax = Calculated tax value
- Multi-Product, with one flagged state and non-flagged TAX state, then Tax = Calculated tax value
- Multi-Product, with one flagged state and non-flagged non-tax state, then Tax = "Not collected"
- Multi-Product, with multiple flagged states, then Tax = "Not collected"
The list of "Flagged States" are: CO, LA, VT The list of TAX states are: AZ, GA, NC, NY, OH, TX
I have the following code:
%%[ /* IF ONLY ONE ITEM, AND STATE=CO, LA, OR VT THEN DISPLAY NOT COLLECTED OTHERWISE DISPLAY TAX VALUE */ IF @brs_item_rowcount <= 1 THEN IF ( @Ship_State == "CO" OR @Ship_State == "LA" OR @Ship_State == "VT" ) THEN SET @TaxDisplay = "Not collected" ELSE SET @TaxDisplay = Format([OrderTax],"$#,#.00") ENDIF /* IF MORE THAN ONE ITEM */ ELSEIF @brs_item_rowcount >= 2 THEN FOR @i = 1 TO @brs_item_rowcount DO SET @ShippingStates = Field(Row(@brs_ship_state,@i),"value") IF @ShippingStates == "" THEN /* Silence is golden */ ELSEIF ( @ShippingStates == "CO" OR @ShippingStates == "LA" OR @ShippingStates == "VT" ) THEN SET @TaxDisplay = "Not collected" ELSEIF ( @ShippingStates != "CO" OR @ShippingStates != "LA" OR @ShippingStates != "VT" OR @ShippingStates != "" ) THEN SET @TaxDisplay = Format([OrderTax],"$#,#.00") ENDIF ]%% %%[ /* INCREMENT FOR LOOP */ NEXT @i ENDIF /* END IF ROWCOUNT STATEMENT */ ]%% <!-- DISPLAY TAX VALUE OR NOT COLLECTED --> %%=v(@TaxDisplay)=%%
The above code, works perfectly for conditions 1, 2, 3, and 6. 4 and 5, the code works sometimes and not other times.
I know the issue why it doesn't work, but I'm not sure what my solution should be.
The problem, is that as it loops through the row values in my FOR loop, it sets the variable @ShippingStates equal to whatever the value for the last item in the count. So if there are two products, and each have a separate shipping state. Then @ShippingState, gets set to the value of whatever the last item is, then @TaxDisplay is set based on that evalutation of the last item. So sometimes it is correct, by chance, and sometimes it is not.
If I was doing this in a different language, I would store all of the @brs_ship_state values in an array, and check if the array contains any of my values. But AMP Script doesn't have any sort of array to work with.
How can I check if a set of values contains any of my conditions, to fix condition 4 and 5 above?