1

I have a client who has up to 42 profile attributes that he wants to display in an email. Some subscribers might have all 42, some might just have 2. I'm trying to use BuildRowsetFromString and a for loop to loop through all of the attributes and only print out an <li> when the attribute is not empty. Here's the code that I tried:

<ul>
%%[

var @station1 = [Station1], 
    @station2 = [Station2],
    @station3 = [Station3], 
    @station4 = [Station4], 
    @station5 = [Station5], 
    @station6 = [Station6],
    @station7 = [Station7], 
    @station8 = [Station8], 
    @station9 = [Station9], 
    @station10 = [Station10], 
    @station11 = [Station11], 
    @station12 = [Station12], 
    @station13 = [Station13], 
    @station14 = [Station14], 
    @station15 = [Station15], 
    @station16 = [Station16], 
    @station17 = [Station17], 
    @station18 = [Station18], 
    @station19 = [Station19], 
    @station20 = [Station20], 
    @station21 = [Station21],
    @station22 = [Station22], 
    @station23 = [Station23],
    @station24 = [Station24], 
    @station25 = [Station25], 
    @station26 = [Station26], 
    @station27 = [Station27],
    @station28 = [Station28], 
    @station29 = [Station29], 
    @station30 = [Station30], 
    @station31 = [Station31], 
    @station32 = [Station32], 
    @station33 = [Station33], 
    @station34 = [Station34], 
    @station35 = [Station35], 
    @station36 = [Station36], 
    @station37 = [Station37], 
    @station38 = [Station38], 
    @station39 = [Station39], 
    @station40 = [Station40], 
    @station41 = [Station41], 
    @station42 = [Station42], 
    @rows,
    @row,
    @rowCount,
    @i

set @stationList = "@station1,@station2,@station3,@station4,@station5,@station6,@station7,@station8,@station9,@station10,@station11,@station12,@station13,@station14,@station15,@station16,@station17,@station18,@station19,@station20,@station21,@station22,@station23,@station24,@station25,@station26,@station27,@station28,@station29,@station30,@station31,@station32,@station33,@station34,@station35,@station36,@station37,@station38,@station39,@station40,@station41,@station42" 

set @rows = BuildRowsetFromString(@stationList,",")
set @rowCount = rowCount(@rows)

if @rowCount > 0 then

    for @i = 1 to @rowCount do 

        var @station
        set @row = row(@rows, @i)
        set @station = field(@row,1)

        ]%%

        <li>Station %%=v(@i)=%%, %%=v(@station)=%%</li>

        %%[

    next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%
</ul>

AMPscript doesn't have arrays, so this makes it tough. Is there a better way to do this?

5

Something like this should work for numbered data extension columns in your sending audience:

%%[

for @i = 1 to 42 do 

    var @station
    set @station = AttributeValue(concat("station",@i))

    if not empty(@station) then 

        ]%%

        <li>Station %%=v(@i)=%%, %%=v(@station)=%%</li>

        %%[

    endif

next @i 

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