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>

,

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.

| improve this answer | |
  • Also a good option. – Kelly J Andrews Dec 2 '14 at 20:48
  • I tend to put the IIF() all inline so I can control the whitespace. – Adam Spriggs Dec 2 '14 at 21:16
  • I suppose its a matter of context. This works well in this case, the other works well in other cases. – Kelly J Andrews Dec 2 '14 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.

| improve this answer | |
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]%%

| improve this answer | |

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.