I have created a dynamic content block, which is meant to be added to our email template. It is a top banner, which should only be shown if a customer have made updates to their basket within the last 5 days.

I'm trying to render the content based on a DE where the @DateToday and @ShopCart is specified, but I can't seem to get the Dynamic content block to show in the emails.

I'm a totally newbie when it comes to AMPScript, so I would like to get some inputs to how to do this the best way.

  • Does the value of @ShopCart come from your sending Data Extension or another one? – Adam Spriggs Mar 23 '17 at 13:20
  • Sorry for my late response, but yes it does come from our sending DE – Trine Mar 27 '17 at 12:06

Assuming the "Customer Basket" DE contains SubscriberKey and a DateTime field, you could do something like this:

In HTML Content Block in Email:

VAR @rows,@lastdate,@today
SET @today = Now()
SET @rows = LookupOrderedRows("CustomerBasket",1,"BasketDate Desc","SubscriberKey",_SubscriberKey)
SET @lastdate = FIELD(ROW(@rows,1), "BasketDate")
IF DateDiff(@today,@lastdate, "D") < 6 THEN]%%
Show 5 Dynamic Content
Nothing to see here

Use LookupOrderedRows to find the latest interaction from a customer (ordered by date, decending).
Take the latest date, and use DateDiff to check if it is within 5 days from today.
If true, show content; else, show nothing.

You may need to check Local/System times, depending on your SFMC setup.
See: LocalDateToSystemDate and SystemDateToLocalDate

  • I tried using what you are suggesting, and I can get it to work when there is any sort of row count - not only abandon cart row count. But as soon as there is no row count at all I get this error message: An error occurred when attempting to evaluate a ContentAreaByName function call. Function Call: ContentAreaByName("my contents\Content Units\Abandon Cart\test topbanner") See inner exception for details. 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(@rows,1) – Trine Mar 27 '17 at 12:08

Okay, I solved the issue with row count, as mentioned in a comment to Cameron. But I have encountered a new issue - It is not taking the latest date and looking max 5 days back, instead it just look after any date from UserLastUpdated. I have a feeling the issues lays within @lastdate, but I am not sure why.


You need to have a if else condition on row count. If row count is 0 then you can show the default content and if its greater than 0 then you can have nested if else conditions and show the dynamic content accordingly.

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.