Home / content / Creating dynamic subject using AMPScript

Creating dynamic subject using AMPScript

0 points
Mauricio Ardila's picture


Today I was reading some of the questions in Code and I found someone asking how to create dynamic subject lines using AMPScript. This reminded me of something cool that I learned a couple of months back.

In the example below, the user is trying to put the full AMPScript in the subject:


        IF @customerStatus == 'New' THEN

set @subjectline = "Get a $%%=v(@giftCardAmount)=%% Gift Card when you make your first purchase."


set @subjectline = "Get a $%%=v(@giftCardAmount)=%% Gift Card."



There are a few problems related to this. One is that he is trying to using inline AMPScript with blocks. Instead, you need to use the Concat function.

%%=Concat("Get a ",@giftCardAmount," Gift Card when you make your first purchase.")=%%  

The cool part is what I figured out couple of months ago. In order to understand this concept, we need to understand how OMM generates each of the emails. First, OMM will try to render the Body of the email creating a namespace for that specific email. After that, OMM will try to render the Subject. This is very powerfull to know because it will allow you to pre-process your subject in the body. For instance,



VAR @Subject

SET @Subject = ‘New test’




As you can see, you will be able to pre-process your subjects in the Body. With this knowledge you can start utilizing other tools like TACA calls that will allow you to have a faster email times. (Yes you can create TACA in the body and then reuse them in the subject)


Credits to  Zack Schultz (ADC) for finding this functionality

Product Group: