0

I am brand new to AMPScript and have a complicated use case I'm hoping somebody could help with. I have data that is being imported into SFMC that relates to offers that a customer may receive. In that data extension, some customers may receive all 5 offers, while others will only receive one.

Is there a way to show content blocks for individuals who qualify (as listed in the data extension) and collapse and hide content for those that don't qualify?

1 Answer 1

0

Below script assumes you have your offers stored with a reference to the Subscriber Key of the recipient. Otherwise you will need to add another identifier in the sendable data extension, allowing you to map the offers to the particular recipient.

It will look for records in that data extension, which match the ID, and show any matching number. If no records are found, it will show the fallback content (after else).

%%[
var @offerRows, @offerRow, @offerRowCount, @subscriber, @i

set @subscriber = AttributeValue(_subscriberkey) /* unique ID of the recipient */
set @offerRows = LookupRows("OfferDataExtension","customer_id", @subscriber)
set @offerRowCount = rowcount(@offerRows)


if @offerRowCount > 0 then

 for @i = 1 to @offerRowCount do

   var @offerLink, @offerName
   set @offerRow = row(@offerRows, @i) /* get row based on counter */
   set @offerLink = field(@offerRow,"link")
   set @offerName = field(@offerRow,"name")

   ]%%

   <br>You qualify for %%=v(@offerName)=%%, you can find it <a href="%%=RedirectTo(@offerLink)=%%">here!</a>

   %%[

 next @i ]%%

%%[ else ]%%

Sorry, no offers for you.

%%[ endif ]%%

I will recommend you exploring some Ampscript resources, to familiarise yourself with the notation. You can start with Trailhead as well as Ampscript.guide

2
  • I'm laughing at "sorry, no offers for you." This is super helpful!! Thank you - I'm going to look into the recommended resources now - I appreciate your help.
    – metnewmex
    Commented Apr 14, 2023 at 20:14
  • You're welcome. You can of course also use ContentBlockByKey, instead of defining the full HTML within the loop. But you can read more on this and other functions in Ampscript Guide. Commented Apr 14, 2023 at 20:39

You must log in to answer this question.

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