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.

2
  • 1
    hey i wanted to edit @lukas Commented Jun 26, 2020 at 10:49
  • 1
    You snooze - you lose, @JohannesSchapdick ;-) Commented Jun 26, 2020 at 10:51

3 Answers 3

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.

2
  • And even more possibilities if you are open to using SSJS! Commented Jun 27, 2020 at 23:17
  • Thanks for this, really useful!
    – Ben Owen
    Commented Jun 30, 2020 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.

1
  • Thanks Johannes!
    – Ben Owen
    Commented Jun 26, 2020 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
]%%

You must log in to answer this question.

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