0

I'm new to Marketing Cloud and I'm trying to find a solution to what I think should be a pretty easy problem. I have an email template in which I would like to insert a date/time, which will be different for every subscriber(it is an appointment date for a reminder email). I have an 'Appointments' data extension where the date/time field is stored, along with the subscriber ID and I wondering the best way to access and display this data inline within my email template.

I looked at using the Lookup function in AMPScript to pull in the data I want, but I'm not sure if this is the best approach and I'm not quite sure of the syntax to make sure that data, once retrieved is displayed in my email.

EDIT: Here's my final code

<div style="display: none">%%[ 

var @rows, @row, @rowCount, @AppointmentDate 
var @subscriberID
set @subscriberID = AttributeValue("subscriberid")

set @rows = LookupRows("Appointments","Contact ID", @subscriberID)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then
    set @row = row(@rows,1) /* get row #1 */
    set @AppointmentDate = field(@row,"Date")
    set @AppointmentDate = format(@AppointmentDate,"MM/dd/yyyy")
else
    set @AppointmentDate = "not found"
endif


]%%
</div>

Your appointment date is: %%=v(@AppointmentDate )=%%

2 Answers 2

0

I have some AMPScript lookup examples on my blog. Here's an example, adjusted for the scenario you described:

%%[
var @rows, @row, @rowCount, @AppointmentTime 
var @subscriberID
set @subscriberID = AttributeValue("subscriberid")

set @rows = LookupRows("Appointments","SubscriberID", @subscriberID)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then
    set @row = row(@rows,1) /* get row #1 */
    set @AppointmentTime = field(@row,"AppointmentTime")
    set @AppointmentTime = format(@AppointmentTime,"hh:mm tt")
else
    set @AppointmentTime = "not found"
endif

]%%

Your appointment time is: %%=v(@AppointmentTime )=%%
2
  • Hi Adam, thank you for your comment. I've got this close to working (need to make a couple unrelated changes to test it on a real subscriber), my code is in an answer below. I changed the lookup value to Email address for this particular data extension, but I wanted to ask if your line 'AttributeValue("subscriberid")' is actually looking up the id of the current subscriber?
    – ZackB
    Commented Oct 4, 2016 at 2:48
  • No, it's it's a personalization string common to all email sends. I used AttributeValue() around it out of habit. It's good for gracefully handling null values. SubscriberID should never be null, so the AttrbuteValue() around it is optional. Commented Oct 5, 2016 at 14:55
0

Here's my updated version of the code:

<div style="display: none">%%[ 

var @rows, @row, @rowCount, @AppointmentDate 
var @subscriberID
set @subscriberID = %%emailaddr%%

set @rows = LookupRows("Appointments","Email Address", @subscriberID)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then
    set @row = row(@rows,1) /* get row #1 */
    set @AppointmentDate = field(@row,"Date")
    set @AppointmentDate = format(@AppointmentDate,"MM/dd/yyyy")
else
    set @AppointmentDate = "not found"
endif


]%%
</div>

Your appointment date is: %%=v(@AppointmentDate )=%%
1
  • Please update your original question and add this code. Commented Oct 5, 2016 at 14:48

You must log in to answer this question.

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