1

What would be the correct script for the following?

%%FieldName%%, fallback = no information available

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
    AttributeValue() is the unsung hero of AMPScript. I use it for any and all personalization strings and it has saved my butt countless times. – Gortonington May 16 '18 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  

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

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.