Thanks for taking your time to review my question. We have a complex situation that we need to use ampscript to display different content based on the webinar attendance. The data is stored in Three data extensions named "audience"(send data),"event(event_ID and Email)","Webinar names(Event_ID,EVent_name)". We have our var set and used "IF" statement for different content display. The issue is when certain audience who has multiple IDs(watched multiple webinar), we are not able to us "IF"statement to display multiple content. I am just wondering if we can achieve this with LOOP function ?

Our desired email would be: Hello %%=v(@firstname)%% Thanks for watching %%=v(@event_name)%%(multiple) Here is more content you might like (Multiple based on the event.

Here's the code we have so far `

%%[ var @subkey, @Fname, @email, @event_id, @rows, @row, @rowCount, @subKey, @counter, @Event_name

set @subKey = subscriberkey
set @Fname = FirstName
set @email = EmailAddress
set @event_id = lookup("event","Event_ID","Email_address", @email)
set @Event_name = Lookup("Webinar names", "Event_Name", "Event_ID", @event_id) 

%%[IF @event_id != "54321" and @event_id != '135135'  THEN]%%

  %%[IF @event_id != "12345" and @event_id != '135135'  THEN]%%

  %%[IF @event_id != "12345" and @event_id != '54321'  THEN]%%
  • Have you tried the loop that was suggested to you in your other question? Commented Jul 25, 2020 at 2:18
  • Also if you could update your question to include some sample data from Event and Webinar names, it would be helpful. Commented Jul 25, 2020 at 2:21
  • Last thing, what are the rules for determining related/suggested based on event attendance? Perhaps we can suggest an alternative to your conditionals. Commented Jul 25, 2020 at 2:41
  • Hello Johannes, sorry for reposting my issue. I have tired Loop that was suggested by Adam and it seems not working. The data is pretty simple, for Event, there are only three fields: email address, event_ID, and first name. The Webinar names : event_id and Event_names. The rules are based on the event id, the email will display the webinar name they watched and the a piece of content that we recommend for them. We tired IF statement but it wasn't able to display two or more webinar names and content if one email relates to two or more event_id from Event table. Thanks for your patience.
    – Bryce Mi
    Commented Jul 26, 2020 at 6:43

1 Answer 1


Here's how I'd approach this -- loop twice through the subscriber's events with the first loop qualifying the events with a matching event_name and looping again to build the output string.

In the recommendation section, you can use the indexOf() function to determine if a person has attended a particular series of events or not and then output the content that's in line with your requirements.

    set @debug = 1

    /* pull email address from system string */
    set @EmailAddress = AttributeValue("emailaddr")
    set @firstName = AttributeValue("FirstName")
    set @attendedEvents = LookupRows('event','Email_address', @EmailAddress)
    set @rowCount = rowcount(@attendedEvents)

    if @debug == 1 then
      output(concat("<br>rowCount: ", @rowCount))

    set @attendedEventNames = ""
    set @attendedEventIds = ""
    set @qualifiedEventCount = 0
    /* qualified event loop -- events with a webinar names match */ 
    for @i = 1 TO @rowCount do

        set @row = row(@attendedEvents,@i) 
        set @eventID = field(@row,'Event_ID')
        set @event_name = Lookup("Webinar names", "event_name", "Event_ID", @eventID)

        if @debug == 1 then
          output(concat("<br>eventID: ", @eventID))
          output(concat("<br>event_name: ", @rowCount))

        if not empty(@event_name) then 

            set @qualifiedEventCount = add(@qualifiedEventCount,1)
            set @attendedEventNames = concat(@attendedEventNames, "|", @event_name)
            set @attendedEventIds =  concat(@attendedEventIds, "|", @eventId)

            /* strip leading delimiter from first element */
            if @qualifiedEventCount == 1 then
                set @attendedEventNames = replace(@attendedEventNames,"|","")
                set @attendedEventIds = replace(@attendedEventIds,"|","")


    next @i

    if @debug == 1 then
      output(concat("<br>qualifiedEventCount: ", @qualifiedEventCount))
      output(concat("<br>attendedEventNames: ", @attendedEventNames))
      output(concat("<br>attendedEventIds: ", @attendedEventIds))

    if @qualifiedEventCount == 0 then
        raiseError("No qualifed events for subscriber", 1) /* skip the send to this subscriber */

    set @attendedEventNamesOutput = ""
    set @qualifiedEventNamesRowset = buildrowsetfromstring(@qualifiedEventNamesRowset,"|")
    set @rowcount = rowCount(@qualifiedEventNamesRowset)

    if @debug == 1 then
      output(concat("<br>rowCount (2): ", @rowCount))

    /* qualified event output loop -- build a punctuated output string */ 
    for @i = 1 to @rowcount do

        set @row = row(@qualifiedEventNamesRowset, @i) 
        set @eventName = field(@row,1)

        if @i == 1 then
          set @attendedEventNamesOutput = @eventName
        elseif @i == @qualifiedEventCount then
          set @attendedEventNamesOutput = concat(@attendedEventNamesOutput, " and ", @eventName)
          set @attendedEventNamesOutput = concat(@attendedEventNamesOutput, ", ", @eventName)  

    next @i


Hello, %%=properCase(@firstName)=%%.  Thanks for watching %%=v(@attendedEventNamesOutput)=%%.
<br><br>Here is more content you might like: 

%%[ /* output content based on events attended  */ ]%%

%%[ if indexOf(@attendedEventIds, "12345") > 0 and indexOf(@attendedEventIds, "23456") == 0 and indexOf(@attendedEventIds, "9876") == 0 then ]%%

    %%[ /* attended 12345, but not 23456 and 9876  */ ]%%
    <p>CONTENT HERE</p>

%%[ elseif indexOf(@attendedEventIds, "2345") == 0 and indexOf(@attendedEventIds, "789") == 0 then ]%%

    %%[ /* attended 2345, but not 789    */ ]%%
    <p>CONTENT HERE</p>

%%[ endif ]%%
  • Hello Adam , Thank you so much for the help. i inserted the proper values for the variables but it gives me this error for every subscriber " if @qualifiedEventCount == 0 then raiseError("No qualifed events for subscriber", 1)". What could be the issue and is there any way for me to troubleshoot ? Thank you
    – Bryce Mi
    Commented Jul 27, 2020 at 13:54
  • Updated my answer above. I had an incorrect variable reference. Commented Jul 27, 2020 at 14:07
  • Hello Adam, thanks for the update. I got another error:Invalid index (parameter 2) passed to Row function. Index must be less than or equal to the row count. Index Value: 1 Row Count: 0 Function: row(@qualifiedEventNamesRowset, @i)
    – Bryce Mi
    Commented Jul 27, 2020 at 14:27
  • I've added a rowcount to the second loop. Commented Jul 27, 2020 at 15:00
  • The > 0 means they attended, the == 0 means they didn't attend. You'll need to own that logic since I'm not privy to your data or requirements -- I'm just providing a framework. Added some debugging statements to you can see the result after each step. Just set @debug = 0 when you're done debugging. Commented Jul 27, 2020 at 15:36

You must log in to answer this question.

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