1

I have a data extension that has a field called "veh_model_name". I want to create an If/then ampscript code to change the value "Lancer SportBack" to "Lancer" but return the regular field values if the values are not "Lancer SportBack". Then I want to place the variable in the subject line of my email. Here is what I have:

%%[
    var @subject
    set @subject = veh_model_name
]%%
%%[IF @subject == "Lancer SportBack" THEN]%%

  Lancer

%%[ELSE]%%

  %%=v(@subject)=%%

  ENDIF
]%%
2
  • Is veh_model_name a field in your data extension? If so it needs to be in [square brackets].
    – TCassa
    Commented Jun 29, 2017 at 8:21
  • Is always good to use AttributeValue("veh_model_name") and checking for empty() Commented Jun 29, 2017 at 14:42

2 Answers 2

2

You didn't retrieve the value correctly and also forgot to open the AMPscript-Block for your ENDIF, which will cause a validation error. So I suggest trying the following code:

%%[
    var @subject
    set @subject = Lookup("NAME_OF_YOUR_DATA_EXTENSION", "veh_model_name", "NAME_OF_THE_EMAIL_COLUMN", AttributeValue("emailaddr"))
]%%
%%[IF @subject == "Lancer SportBack" THEN]%%

  Lancer

%%[ELSE]%%

    %%=v(@subject)=%%

%%[ENDIF]%%

The only things you need to modify are:

  • replace NAME_OF_YOUR_DATA_EXTENSION with the name of your data extension
  • replace NAME_OF_THE_EMAIL_COLUMN with the name of the column containing the email address in your data extension
5
  • Hi Markus, Thanks for responding, I entered the code above into my HTML code within <script></script> section. also plae the Ampscript variable %%=v(@subject)=%% in the subject line "Your %%=v(@subject)=%% anniversary is almost here.". but when I create a send preview. I do not see any values from my DE. This is how it looks. "Your anniversary is almost here." I am not sure why that is?
    – David Mc
    Commented Jun 29, 2017 at 14:15
  • You don't need to place AMPscript code inside a script-tag. Place the code whereever you like to output the variable. Is your data extension the entry event's data extension? This is necessary for the code above to work. Otherwise you need to look the field up in the other data extension querying it by the primary key. Commented Jun 29, 2017 at 14:18
  • Hi Markus, I am just getting my feet wet using SFMC so the jargan terminology of SFMC i do not have down pack yet. I am assuming you mean if the DE is having data imported by a form or landing page of some sort. If so, then no it's not an entry event data extension. It's just mass of data records that was imported to a DE. So I would have to do field look up. I have two primary keys "vin" and "email adrress". How do I look these up? Thanks for you help.
    – David Mc
    Commented Jun 29, 2017 at 14:59
  • Where are you using the amp script? In an email? If so, how is this email sent? Is it sent from journey builder? A journey has an entry event hat starts it and this event has a data extension (which is the entry event data extension). Commented Jun 29, 2017 at 15:01
  • I am using the amscript in the subject line of the email, under properties. Oh ok no I am not using journey builder. I am sending the email as a "guided send".
    – David Mc
    Commented Jun 29, 2017 at 15:11
-1

A good AMPscript Language documentation is mentioned here for reference: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/languageElements.htm

1
  • 2
    Welcome to SFSE! Please take the tour and read How to Answer. Links alone tend not to be good answers (even if they are to the official documentation). To me, this answer feels incomplete. The OP (Original Poster of the question) appears to have a grasp on the basics, but was asking for help in figuring out what their syntax error was. I think the other existing answer is a good template. It covers what OP's issue is, and how to fix it. Including some explanation as to why the fix works is also a generally good idea.
    – Derek F
    Commented Nov 28, 2018 at 17:41

You must log in to answer this question.

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