I'm trying to display dynamic content in an email for users who completed modules on the client's website. For each module completed, there is a Badge_ID that is added to the data extension "Badge_DE". The user (identified by the unique Account_ID variable) can have multiple badges in the same data extension, however, each time the user earns a new badge, their record gets add to a new row in the data extension (there is only one column for the Badge_ID field, so unless a new row is added, the previous Badge_ID variable would be overwritten).

I'm trying to establish logic in the ampscript that will review all the rows for each unique Account_ID and display the content depending on which badges the unique user has. It seems that the ampscript below is not doing this and is only picking up the Badge_ID for the first instance of the unique Account_ID it finds in the data. SFMC support told me to use a for loop but I've never implemented that before and I'm not sure where to start. Any advice will be greatly appreciated!

%%[ var @rc1_rows, @rc1_row, @rc1_rowCount var @rc1_lookupValue set @rc1_lookupValue = AttributeValue("Account_ID")

set @rc1_rows = LookupRows("Table_1","Account_ID", @rc1_lookupValue) set @rc1_rowCount = rowcount(@rc1_rows)

if @rc1_rowCount > 0 then

var @rc1_rep_account_id set @rc1_row = row(@rc1_rows,1) set @rc1_rep_account_id = field(@rc1_row,"Account_ID") var @rc2_rows, @rc2_row, @rc2_rowCount var @rc2_lookupValue set @rc2_lookupValue = @rc1_rep_account_id

set @rc2_rows = LookupRows("Badge_DE","Account_ID", @rc2_lookupValue) set @rc2_rowCount = rowcount(@rc2_rows)

  if @rc2_rowCount > 0 then
      var @rc2_badge_id
      set @rc2_row = row(@rc2_rows,1)
      set @rc2_badge_id = field(@rc2_row,"Badge_ID")


%%[IF ((@rc2_badge_id != "1115137")) THEN]%%

Content Displayed 1

%%[ELSEIF ((@rc2_badge_id == "1115137")) AND ((@rc2_badge_id != "2034203")) THEN ]%%

Content Displayed 2

%%[ELSEIF ((@rc2_badge_id == "1115137")) AND ((@rc2_badge_id == "2034203")) THEN ]%%

Content Displayed 3



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.