0

Trying to figure out a way to return a value from a Field in a data extension only if the field is non-blank.

I want to send an email with a personalized greeting ("Hey, First Name! Here's this week's content") but the issue I'm running in to is that not everyone has provided their first name.

I'm wondering if there's a way to run a check that says

If first name is blank then return "Here's this week's content" else Return "Hey, First Name, Here's this week's content".

1

This is a common case for AMPscript, and there are various ways to accomplish this. I prefer this method, whereby all the copy and logic lives in the AMPscript block, with just the result being shown in the HTML.

<html>
<head>
    %%[
    SET @firstname = AttributeValue("FirstName")
    SET @SalutationA = Concat("Hey, ",@firstname," Here's this week's content")! 
    SET @SalutationB = "Here's this week's content"

    IF @firstname == "" THEN
      SET @text = @SalutationB 
    ELSE
      SET @text = @SalutationA
    ENDIF

    ]%%

</head>
<body>
  <p>%%=v(@text)=%%</p>
</body>
</html>
  • This solutions seems quite elegant. However, when I tried to implement I got the error: The script condition contains an invalid comparison operator. Condition: @firstname = "" Is there another way I should be looking at a cell containing a null value? – Eczekner Dec 15 '17 at 12:57
  • it needs to be two equal signs. "==" – Gortonington Dec 15 '17 at 14:30
  • Also can use IF EMPTY([at]firstname) and I would change the first variable to be SET [at]firstname = AttributeValue("FirstName") as this will better handle NULL values and more.(Plus it will make @AdamSpriggs happy and we all want that!) [at] used in place of 'commercial at' sign as comment will only let me use one. – Gortonington Dec 15 '17 at 14:37
  • This all makes sense to me, but for some reason SalutationA is returning "Hey, @firstname! Here's this week's content" rather than filling in firstname with the actual name. – Eczekner Dec 15 '17 at 18:22
0

You can use ampscript if statement something like:

%%[ If Not Empty @firstname Then ]%% 
show first name here
%%[ Else ]%%
show backup if empty
%%[ Endif ]%%

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.