0

I have a data extension like below. Now when sending emails to the list it sends multiple emails to a single subscriber based on the record. As an example as - [email protected] is two times in the table so it sends two separate emails. I need to do two things -

  1. Send a single email if there multiple records with the same email address.
  2. Add all the details to a single email for a single user with multiple records.

Currently, I am using the below code and it shows all rows value in a single email for a similar email address. The output of the code is listed below -

email_address: [email protected]
Row 1, firstName: Eileen, lastName: Dover
Row 2, firstName: Eileen, lastName: Dover

So it shows two different record values in a single email but it sends the email two times as there are two records for the email address - [email protected]

%%[
var @rows, @row, @rowCount, @i, @email_address, @user_code, @first_name, @last_name, @order_details

set @email_address = email_address
set @user_code = user_code

set @rows = LookupRows("TestDE","email_address", @email_address)
set @rowCount = rowcount(@rows)

output(concat("email_address: ", @email_address))

if @rowCount > 0 then

  for @i = 1 to @rowCount do

    var @first_name, @last_name, @order_details
    set @row = row(@rows, @i) /* get row based on counter */
    set @first_name = field(@row,"first_name")
    set @last_name = field(@row,"last_name")

    ]%% <br>
    Row %%=v(@i)=%%, firstName: %%=v(@first_name)=%%, lastName: %%=v(@last_name)=%%

    %%[

  next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%

Here is the table structure -

UserID FirstName LastName OrderDetails ItemNumber Email
123456 Eileen Dover abcdef 01 [email protected]
567890 John White xyzuvv 02 [email protected]
123456 Eileen Dover abrcdd 03 [email protected]
567890 John White ertvvb 04 [email protected]
456789 Jane Banks uerthy 05 [email protected]

So can anyone please help me to figure out the issue so that it will send a single email for all the records if there similar email address multiple times. Hope that makes sense.

Thanks!

0

0