Sorry for the weird title, but this is an odd one I think.
We have been testing a unique coupon code send using a data extension. There are many examples on the internet of using AMPScript to do this, ie, go through a series of rows of unique coupon codes and use each code only once.
The data extension has FirstName, CouponCode, EmailAddress. The csv we uploaded matches this exactly. The email template has merge fields for FirstName and EmailAddress
This is the problem we have experienced:
- Upload the csv - check in the data extension an the records are there and the name and email in each row match
- Send the email. Emails all send just fine, except...
- Received emails have the wrong name for the email address
- Recheck the records in data extension, and they are now jumbled (ie the name and email in each row are not matching)
After much messing around, we figured out that the position of the FirstName in the list of records does not change, but the position of the email address does. The email addressed become sorted in alphabetical order after we send. This is what causes the mismatch.
Records in data extension before send:
| Name | Email |
| Jeff | firstname.lastname@example.org |
| Ben | email@example.com |
Records in data extension after send:
| Name | Email |
| Jeff | firstname.lastname@example.org |
| Ben | email@example.com |
So the question is, why? Does anybody know?
Below is amp script code for reference. Thanks
%%[ var @em, @CouponRow, @CouponCode, @FirstName if _messagecontext == "PREVIEW" then set @FirstName = "XX TEST NAME XX" set @couponCode = "XX TEST CODE XX" else /* include your sendable attribute/column here */ set @em = AttributeValue("emailAddr") set @CouponRow = ClaimRow("TEST_Vouchers", "isClaimed", "Email", @em) if empty(@CouponRow) then /* You can do other error handling here if you want.*/ /* This aborts the send */ RaiseError("No coupons available", false) else SET @FirstName = Field(@CouponRow, "FirstName") SET @CouponCode = Field(@CouponRow, "CouponCode") endif endif ]%%
Merge fields are: