1

What would be the correct script for the following?

%%FieldName%%, fallback = no information available

2 Answers 2

5

This is how I would approach it:

%%[

var @fieldName 
set @fieldName = AttributeValue("fieldName")

if not empty(@fieldName) then
]%%

%%=v(@fieldName)=%%

%%[ else ]%%

no information available

%%[ endif ]%%

or in a single block:

%%[

var @fieldName 
set @fieldName = AttributeValue("fieldName")

if not empty(@fieldName) then

  output(concat(@fieldName))

else 

  output("no information available")

endif 
]%%

or shorter:

%%=iif(empty(AttributeValue("fieldName"), "no information available", AttributeValue("fieldName")))=%%

Using raw personalization strings is risky, IMO. If fieldname didn't exist in your send context for some reason, the email would blow up. Using AttributeValue() will return an empty string in that case.

1
  • 1
    AttributeValue() is the unsung hero of AMPScript. I use it for any and all personalization strings and it has saved my butt countless times. Commented May 16, 2018 at 12:38
0
%%[ var @this set @this = FieldName]%% 
%%[IF @this == "" or @this is NULL THEN]%% 
some text here to signify that it's blank 
%%[ELSE]%% %%FieldName%%, 
%%[ENDIF]%%

Taken from: https://help.salesforce.com/articleView?id=000213691&type=1  

1
  • Thanks Harley. Then if it was %%FieldName%% or %%FieldName%%, fallback = no information available would you know what it would be?
    – Keith
    Commented May 16, 2018 at 1:36

You must log in to answer this question.

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