3

I am working on AMPScript for an email greeting for the first time. I'm trying to make it so if we don'thave a specific First Name (Preferred Guest), the default is Greetings, otherwise it should be First Name. When I run the code, the error I get is that the IF statement is not closed... but I have %%[ENDIF]%% .... Thoughts?

My code:

<script runat=server language=ampscript>

%%[
Var @fname

Set @fname = FirstName

]%%%%[if @fname =="Preferred Guest" then]%%
Greetings,
%%[else]%%
%%= v(@fname) =%%%%[ EndIf ]%%


</script>

,

3 Answers 3

4

They way I'd put it would be as follows:

%%[ SET @greeting = IIF( FirstName == "Preferred Guest", "Greetings," FirstName ) ]%%
%%=v@(greeting)=%%
...

See the function reference here.

3
  • Also a good option. Commented Dec 2, 2014 at 20:48
  • I tend to put the IIF() all inline so I can control the whitespace. Commented Dec 2, 2014 at 21:16
  • I suppose its a matter of context. This works well in this case, the other works well in other cases. Commented Dec 2, 2014 at 22:39
2

AMPscript does not require <script runat=server language=ampscript> and it's causing the send engine to freak out a bit with the opening and closing blocks etc.

Here would be a better way to write this block -

%%[IF FirstName =="Preferred Guest" THEN ]%%
  Greetings,
%%[ELSE]%%
  %%FirstName%%
%%[ENDIF]%%

You don't need to set the FirstName attribute to a variable - it's already available to your message as a replacement string.

1

Your syntax looks good, does it work though if you remove the spaces around v(@fname)?

%%[ Var @fname Set @fname = FirstName ]%%

%%[if @fname == "Preferred Guest" then]%%

Greetings,

%%[else]%%

%%=v(@fname)=%%

%%[EndIf]%%

You must log in to answer this question.

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