0

I've been having some difficulty getting my loop to work properly and was hoping someone could take a look.

The campaign is a recipient is assigned a tier (in this case 1-8), the audience data extension has this listed in [segmentB] The first portion of the email takes this tier and matches the tier to the [GIFTID] column and places the relevant data into variables for the guaranteed gift. What I am trying to do is to select the gift above that tier (IF segmentB == 2, select GIFTID 3) and repeat until the list is exhausted, each time setting the variables for that section of code.

The following AMPscript will pull in one row below the segmentB value, but will simply stop. I assume because it will lookup the row set of the unique "GIFTID" value it does not repeat the lookup on the next loop, but I am not entirely sure.

%%[SET @UPGRADEID = Add(segmentB,1)
SET @rows = LookupRows("UEL_PLAY_EARN_TV_01_LOOKUP","GIFTID", @UPGRADEID)

FOR @i = 1 TO RowCount(@rows) DO
  SET @CurrentRow = Row(@rows,@i)

  SET @IMGURL = Field(@currentrow,"IMGURL")
  SET @DESC = Field(@currentrow,"DESC")
  SET @UNIQUEID = Field(@currentrow,"UNIQUEID")

  IF SEGMENTA == "S" THEN
    SET @EARN = Field(@currentrow,"SEARN")
  ELSEIF SEGMENTA == "V" THEN
    SET @EARN = Field(@currentrow,"VEARN")
  ENDIF
]%%

<table>
</table>

%%[ 
NEXT @i
]%%

2 Answers 2

0

With first lookup you will always retrieve one or none rows and it won't increment. If in UEL_PLAY_EARN_TV_01_LOOKUP your rows use 1-8 unique GIFTID attribute, try something like this:

SET @UPGRADEID = Add(segmentB,1)
SET @DEROWCOUNT = DataExtensionRowCount("UEL_PLAY_EARN_TV_01_LOOKUP")
IF @DEROWCOUNT >= @UPGRADEID THEN
    FOR @i = @UPGRADEID TO @DEROWCOUNT DO
        SET @GIFTROWS = LookupRows("UEL_PLAY_EARN_TV_01_LOOKUP","GIFTID", @i)
        IF RowCount(@GIFTROWS) == 1 THEN
            SET @CurrentRow = Row(@GIFTROWS, 1)
            /*do something here*/
        ENDIF
    NEXT @i
ENDIF
0

If you're getting unexpected results, try adding some outputline() functions to display the values.

Something like this:

%%[

var @segmentA, @segmentB, @upgradeid, @rows, @rowCount, @currentRow, @imgurl, @desc, @uniqueid, @earn

set @segmentA = AttributeValue("segmentA")
set @segmentB = AttributeValue("segmentB")

SET @upgradeid = Add(@segmentB,1)
SET @rows = LookupRows("UEL_PLAY_EARN_TV_01_LOOKUP","GIFTID", @upgradeid)
set @rowCount = rowcount(@rows)

outputline(concat("<br>segmentA: ",@segmentA))
outputline(concat("<br>segmentB: ",@segmentB))
outputline(concat("<br>upgradeid: ",@upgradeid))
outputline(concat("<br>rowCount: ",@rowCount))

if @rowCount > 0 then

  FOR @i = 1 TO @rowCount DO

      SET @currentrow = Row(@rows,@i)

      SET @imgurl = Field(@currentrow,"imgurl")
      SET @desc = Field(@currentrow,"desc")
      SET @uniqueid = Field(@currentrow,"uniqueid")

      IF @segmentA == "S" THEN

        SET @earn = Field(@currentrow,"SEARN")

      ELSEIF @segmentA == "V" THEN

        SET @earn = Field(@currentrow,"VEARN")

      ENDIF

      outputline(concat("<br> imgurl: ",@imgurl))
      outputline(concat("<br> desc: ",@desc))
      outputline(concat("<br> uniqueid: ",@uniqueid))
      outputline(concat("<br> earn: ",@earn))

  NEXT @i

else

  outputline(concat("<br>row not found"))

endif
]%%

You must log in to answer this question.

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