0

I am super new to using AMPScript and have been watching some videos and browsing this forum and have been putting in the exact same IIF statements but I have been getting this error:

The subscriber preview failed to generate. Review the details, correct all issues, and try again.

An error occurred when attempting to resolve a function call. See inner exception for detail.

Function Call: IIF(EMPTY(Contact First Name), "There", (Contact First Name) Index: 18226 TransCode Type: HTML Content Type: HTML Substitution Level: Subscriber Message Context: Preview

An error occurred when attempting to resolve a script expression. See inner exception for detail. Script Expression: EMPTY(Contact First Name) MemberID: 1052936 JobID: 0

Invalid characters appear at the end of the parameter value Function Call: EMPTY(Contact First Name) Parameter Value: Contact Invalid Character: F

The token works when I just have:

Hi %%Contact First Name%%

But I am trying to add a fallback so if the Contact First Name field is empty I would like it to say, "Hi," but if the field has a name it should generate, "Hi John,"

Hi %%=IIF(EMPTY(Contact First Name), ",", (Contact First Name)=%%,

What is broken with my IIF statement?

2
  • IF has a single "I", not two of them...
    – Derek F
    Dec 22, 2023 at 22:52
  • I am using an Inline IF
    – rnkwill
    Dec 22, 2023 at 22:58

2 Answers 2

2

Don't use naked personalization strings!

AttributeValue() will return an empty string if the contextual variable doesn't exist -- or in your case, contains a space.

Generally speaking you can surround these personalization strings in square brackets when they contain spaces (e.g. [Contact First Name], but you might as well just use AttributeValue().

%%[

set @ContactFirstName = AttributeValue("Contact First Name")

]%%
<!-- Other HTML --> 
Hi %%=IIF(EMPTY(@ContactFirstName), "there", @ContactFirstName)=%%,
1
  • This works thanks for the help! If I wanted to get rid of "there" and have it display as "Hi," without the space after Hi when there's no name and have a space after "Hi ContactName,". Is there a way to concatenate it?
    – rnkwill
    Dec 23, 2023 at 4:03
0

re: This works thanks for the help! If I wanted to get rid of "there" and have it display as "Hi," without the space after Hi when there's no name and have a space after "Hi ContactName,". Is there a way to concatenate it? –

You should be able to just do this -

%%[

set @ContactFirstName = AttributeValue("Contact First Name")

]%%

Hi %%=IIF(EMPTY(@ContactFirstName), "", concat(" ", @ContactFirstName))=%%,

You must log in to answer this question.

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