1

We are setting up an invitation for an event in Marketing Cloud and want to include in the message %%salutation%% are invited to xx event however if the salutation is a single name we would like to append and Partner to the name so it reads %%salutation%% and Partner are invited to xx event

Our salutation data field follows this format:

  • Name
  • Name, Name, Name
  • Name and Name
  • Name & Name

So if there is a comma, & or and then don't show "and partner"

Is this something you could do with AMPscript or is there a better way to do this?

1 Answer 1

4

You could use a conditional utilizing the indexOf AMPscript function to determine if your salutation contains the words and punctuation you described:

%%[

  var @salutation, @salutationSuffix

  set @salutation = AttributeValue("salutation")
  set @salutationSuffix = " and partner"

  if indexOf(@salutation, ",") > 0 
     or indexOf(@salutation, " and ") > 0 
     or indexOf(@salutation, " & ") > 0 
     or indexOf(@salutation, " & ") > 0
     or empty(@salutation) then 

     set @salutationSuffix = "" 

  endif 

  set @saluation = iif(empty(@salutation), "You ", @salutation)

]%%

%%=v(@salutation)=%%%%=v(@salutationSuffix)=%% are invited to xx event.

I think it'd also be good to include handling for salutations that are empty. The iif (inline-if) and empty functions can be used for that.

1
  • Worked perfect, thanks
    – Andyw
    Commented Feb 12, 2020 at 1:48

You must log in to answer this question.

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