one of my clients is trying to build content block trip recommendations based on subscribers attributes and defined logic which looks at boolean fields. The trip recommendations data is held in a non sendable DE.

I was able to build the logic and pull in the content based on the requirements but where I have issues is to actually limit the number of recommendations. For example they are trying to do one recommendations based on a trip budget + destination + a bunch of boolean fields that need to go in a specific order.

Code is below:


    set @ContactID=AttributeValue('Contact ID')
    set @emailAddress = AttributeValue('Email')
    set @Destination = AttributeValue('Destination_NextTrip')
    set @TripBudget= AttributeValue('TripBudget_NextTrip')
    set @LengthDays= AttributeValue('LengthDays_NextTrip')
    set @TravelPref= AttributeValue('TravelPref_NextTrip')
    set @Mindful=AttributeValue('MindfulConsciousTraveller_FutureTravel_attitude')
    set @Cruise=AttributeValue('Cruise_NextTravelExperience')
    set @Outdoors=AttributeValue('Outdoors_NextTravelExperience')
    set @CityBreak=AttributeValue('CityBreak_NextTravelExperience')
    set @Romantic=AttributeValue('Romantic_NextTravelExperience')

    set @rowss = LookupRows("Find your Trip BOZI","Default","1")
    set @rowCounts = rowcount(@rowss)

if @rowCounts > 0 then

    set @matchMindful =0 
    set @matchCruise = 0 
    set @matchOutdoors =0 
    set @matchCityBreak = 0
    set @matchRomantic = 0

for @j = 1 to @rowCounts do

    if (@matchMindful == 0 or @matchCruise == 0 or @matchOutdoors ==0 or @matchCityBreak == 0 or @matchRomantic == 0) then
        set @rowj = row(@rowss, @j) /* get row based on counter */
        set @DestinationNonSendable = field(@rowj,"Destination_NextTrip")
        set @TripBudgetNonSendable = field(@rowj, "TripBudget_NextTrip") 
        set @LenghtDaysNonSendable = field(@rowj, "LengthDays_NextTrip")
        set @name = field(@rowj, "name")
        set @description = field(@rowj,"description")
        set @LinkTrip=field(@rowj,"trip_url")
        set @UrlFinal=RedirectTo(@LinkTrip)
        set @defaultURl='https://www.trafalgar.com'
        set @Image = field(@rowj,"imageURL")
        set @nolink=''
        set @MindfulNonSendable = field(@rowj,"MindfulConsciousTraveller_FutureTravel_attitude")
        set @CruiseNonSendable = field(@rowj,"Cruise_NextTravelExperience")
        set @OutdoorsNonSendable = field(@rowj,"Outdoors_NextTravelExperience")
        set @CityBreakNonSendable = field(@rowj,"CityBreak_NextTravelExperience")
        set @RomanticNonSendable = field(@rowj,"Romantic_NextTravelExperience")
        if (@Destination == @DestinationNonSendable) and (@TripBudget == @TripBudgetNonSendable) and (@Mindful == 'True') and (@MindfulNonSendable == 'True') then 
            set @matchMindful =1 
        elseif (@Destination == @DestinationNonSendable) and (@TripBudget == @TripBudgetNonSendable) and (@Cruise == 'True') and (@CruiseNonSendable == 'True') then 
            set @matchCruise = 1
        elseif (@Destination == @DestinationNonSendable) and (@TripBudget == @TripBudgetNonSendable) and (@Outdoors == 'True') and (@OutdoorsNonSendable == 'True') then 
            set @matchOutdoors=1
        elseif (@Destination == @DestinationNonSendable) and (@TripBudget == @TripBudgetNonSendable) and (@CityBreak == 'True') and (@CityBreakNonSendable == 'True') then 
            set @matchCityBreak=1
        elseif (@Destination == @DestinationNonSendable) and (@TripBudget == @TripBudgetNonSendable) and (@Romantic == 'True') and (@RomanticNonSendable == 'True') then 
            set @matchRomantic = 1 

            set @matchMindful =0 
            set @matchCruise = 0 
            set @matchOutdoors =0 
            set @matchCityBreak = 0
            set @matchRomantic = 0
        endif /* closing the if/elseif matching loop */
    endif /* this closes if @matchMindful == 0 and the other ==0 */   
    if (@matchMindful==1 or @matchCruise ==1 or @matchOutdoors ==1 or @matchCityBreak==1 or @matchRomantic ==1) then ]%%

        Mindful from Sendable DE: %%=v(@Mindful)=%% || Mindful from non sendable DE: %%=v(@MindfulNonSendable)=%%
        Cruise from sendable DE: %%=v(@Cruise)=%% || Cruise from non sendable DE: %%=v(@CruiseNonSendable)=%%
        Outdoors from sendable DE: %%=v(@Outdoors)=%% || Outdoors from Non Sendable DE: %%=v(@OutdoorsNonSendable)=%%
        City Break from sendable DE: %%=v(@CityBreak)=%% || City Break From non sendable DE: %%=v(@CityBreakNonSendable)=%%
        Romantic from sendable DE: %%=v(@Romantic)=%% || Romantic from Non Sendable DE: %%=v(@RomanticNonSendable)=%%
        This is block 1 stuff match on destinaton and budget and <b>a match on one of the above</b>:
        Destination from Sendable DE: %%=v(@Destination)=%% ||| <br>Destination from non sendable DE: %%=v(@DestinationNonSendable)=%% 
        Budget from Sendable DE: %%=v(@TripBudget)=%% ||| <br> Budget from non sendable DE: %%=v(@TripBudgetNonSendable)=%%
        name: %%=v(@name)=%%

    %%[ endif /* closes (@matchMindful==1 or @matchCruise ==1 or @matchOutdoors ==1 or @matchCityBreak==1 or @matchRomantic ==1) */ ]%%

%%[ next @j ]%%

%%[ endif /* closes rowcounts */ ]%%

With this I am able to bring the correct articles that match either the branches in the logic but I need to be able to "stop" the matching process in the for loop once 1 match has been found. I have added a print screen of what I get in the send preview. I hope it makes sense.

I had a similar question last year where I was recommended to add the switch break in the for loop @j== @rowcounts but if I add it in my code I don't get any results.

thank you, Giulietta

1 Answer 1


Where you have this row of code (just before the outputting HTML part) -

IF (@matchMindful == 1 OR @matchCruise == 1 OR @matchOutdoors == 1 OR @matchCityBreak == 1 OR @matchRomantic == 1) THEN ]%%

Change it to this -

IF (@matchMindful == 1 OR @matchCruise == 1 OR @matchOutdoors == 1 OR @matchCityBreak == 1 OR @matchRomantic == 1) THEN 
    SET @rowCounts = @j]%%

The thing is that you cannot set variable @j since it is used for the loop however you can set @rowCounts to be equal to @j and that will stop the loop once the conditions are met.

You must log in to answer this question.

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