6

OK. So I have read all of the documentation, and tried this on my own, but this is all still coming up Japanese to me. I need help writing the code I need to bring data in from an extension to create unique offers within an email.

The Data Extension exists of the subscribers LoyaltyID (which will link them to their list), an offer image (OfferImage1), an offer savings amount (OfferSavings1), an offer description (OfferDesc1), and an offer URL (OfferURL1). Each offer is generated for each individual uniquely. The data for these offers is stored in the Data Extension (Test_DataExtension).

The offer field will appear like this (there will be three offers total):

enter image description here

Is there anyone out there who can help me write the code for this?

  • 1
    Welcome to SFSE! Is it at all possible to copy/paste the code in the question above, instead of the screen shot? Make it easier for us to reuse your code if we need to. – Kelly J Andrews Mar 25 '14 at 21:17
5

In order to grab information from a data extension, there is one of two ways to go about this.

1. Using a non-Sendable Data Extension

When you use a non-sendable data extension, you need to individually lookup each item based on the current subscriber's email address, subscriber key, or some other identifier. Here is a code snippet that shows how this would work:

%%[
SET @rowset = LookupRows("Offers","EmailAddress", emailaddr)
SET @row = Row(@rowset, 1)
]%%

%%= Field(@row, "OfferImg")=%%<br>
%%= Field(@row, "LoyaltyID")=%%<br>
%%= Field(@row, "OfferDesc")=%%<br>
%%= Field(@row, "OfferSavings")=%%<br>
%%= Field(@row, "OfferURL")=%%<br>

You would get a @rowset based on the identifier (in this case emailaddr). You would then grab the first row (in most cases it's the first row, but not always). You would then grab the specific field from that particular @row. @rowset and @row can be named anything, I'm using very literal variable names here. You grab each field using the Field() function, passing in tow parameters, the row and the column name, like below:

%%= Field(@row, dataExtensionColumnName)=%%

2. Using a Sendable Data Extension

This simplifies your code quite a bit when you send an email to a sendable data extension. Each row in your sendable data extension should be unique in this case, as each row would be a new email that is sent. The same results as above would be produced with:

%%OfferImg%%<br>
%%LoyaltyID%%<br>
%%OfferDesc%%<br>
%%OfferSavings%%<br>
%%OfferURL%%<br>

Sendable data extension fields behave just like list attributes, so that personalization strings like the above code shows work. Note: Attributes take precedence here, meaning that if you have LoyaltyID in your list attributes, and LoyaltyID in your sendable data extension, the list attribute's LoyaltyID would be the value used.

2

You are referencing field names using %%= FIELD NAME =%% in order to reference a Sendable Data Extension's field you'll need to remove the = sign. Simply enter %%FIELD NAME%% will give you the value.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.