0

Trying to build out a piece of dynamic content where a different bit of copy will display depending on a users loyalty points.

With one variable the following works:

%%[Var @Loyalty Set @Loyalty = [Loyalty]]%% 

%%[IF Empty(@Loyalty) OR @Loyalty == "1" 
THEN set @defaultValue = "1" 
ELSE set @defaultValue = "other" 
Endif]%% 

%%=v(@defaultValue)=%%

But when it comes to introducing ELSE or ELSEIF functions to query different numbers of loyalty points things start breaking.

%%[Var @Loyalty Set @Loyalty = [Loyalty]]%% 

%%[IF Empty(@Loyalty) OR @Loyalty == "1" 
THEN set @defaultValue = "1" 
ELSEIF @Loyalty Set == "2" 
THEN set @defaultValue = "2" 
ELSE set @defaultValue = "other" 
Endif]%% 

%%=v(@defaultValue)=%%

Any help would be massively appreciated.

  • 1
    hey i wanted to edit @lukas – Johannes Schapdick Jun 26 at 10:49
  • 1
    You snooze - you lose, @JohannesSchapdick ;-) – Lukas Lunow Jun 26 at 10:51
1

I know you already got an answer, but I wanted to add a quick tip in case it could assist you in the future.

If you have a ton of options for your loyalty points, all those conditionals can become insufferable and difficult to maintain. I would then recommend simplifying it with something like the below:

SET @Loyalty = AttributeValue("Loyalty")
SET @defaultValue = "other"
SET @maxValue = 7  /* This sets the max points that could fill in Loyalty */

IF NOT EMPTY(@Loyalty) AND @Loyalty > 0 THEN

  FOR @i=1 TO @maxValue DO

    IF @defaultValue == "other" THEN
      IF @Loyalty == @i THEN
        SET @defaultValue = @i
      ENDIF
    ENDIF

  NEXT @i

ENDIF

Basically what this does is loop through your if statement in each iteration until it finds a match. Once the match is found, although the FOR loop continues, it does not run anything inside - greatly reducing the processing required. This also verifies if there is a value and that value is greater than 0 before beginning the loop to remove unnecessary conditionals. AND by setting the default value to 'other' above everything, it no longer requires you to push ELSE statements inside your conditionals as this is already defaulted correctly.

The maxValue variable is the top point value that is allowed inside of Loyalty value. Also I would highly recommend utilizing AttributeValue() for all your personalization string uses.

| improve this answer | |
  • And even more possibilities if you are open to using SSJS! – Gortonington Jun 27 at 23:17
  • Thanks for this, really useful! – Ben Owen Jun 30 at 14:52
0
%%[
Var @Loyalty
Set @Loyalty = [Loyalty]
]%% 

%%[
IF Empty(@Loyalty) OR @Loyalty == "1" THEN 
  set @defaultValue = "1" 
ELSEIF @Loyalty == "2" THEN 
  set @defaultValue = "2" 
ELSE
  set @defaultValue = "other" 
Endif
]%% 

%%=v(@defaultValue)=%%

You had a "SET" that has broken your script on the first elseif statement. Try to always align the code properly regardin the spacing.

| improve this answer | |
  • Thanks Johannes! – Ben Owen Jun 26 at 10:55
0

In classic fashion, have found a solution that works after posting...

%%[
VAR @Loyalty, @defaultValue
SET @Loyalty = [LoyaltyPoints]

IF @Loyalty == 1 THEN SET @defaultValue = 'text'
ELSEIF @Loyalty == 2 THEN SET @defaultValue = 'text'
ELSEIF @Loyalty == 3 THEN SET @defaultValue = 'text'
ELSEIF @Loyalty == 4 THEN SET @defaultValue = 'text'
ELSEIF @Loyalty == 5 THEN SET @defaultValue = 'text'
ELSE SET @defaultValue = ' '

ENDIF
]%%
| 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.