简体   繁体   中英

If contains operators in AMPscript

At the top of my newsletter I bring salutation and last name information but I don't want to show the value in Salutation directly. I used below Amscript but apparently it only checks the first value then brings "mevrouw" regardlessly.

Geachte %%[ IF [Salutation] == 'De weledelgeleerde heer' 
OR 'De weledelzeergeleerde heer' 
OR 'De hooggeleerde heer' THEN ]%% heer
 %%[ ELSE ]%% mevrouw %%[ ENDIF ]%% %%Last Name%%,  

Can we change this code something like this:

if salutation contains "heer" then bring "heer" else "mevrouw"

Thank you.

I'd recommend using the indexOf AMPscript function. I'd also use an init block to defensively check your raw personalization strings.

%%[ 

var @Salutation
var @lastName
set @Salutation = AttributeValue("Salutation")
set @lastName = AttributeValue("Last Name")
set @lastName = properCase(@lastName)

]%%

Geachte 

%%[ IF indexOf(@Salutation,'heer') > 0 then ]%%

  heer

%%[ ELSE ]%% 

  mevrouw 

%%[ ENDIF ]%% %%=v(@lastName)=%%,

Or inline:

%%[ 

var @Salutation
var @lastName
set @Salutation = AttributeValue("Salutation")
set @lastName = AttributeValue("Last Name")
set @lastName = properCase(@lastName)

]%%
Geachte %%=iif(indexOf(@Salutation,'heer') > 0,"heer","mevrouw")=%% %%=v(@lastName)=%%,

Thank you Adam. It works and I understand the logic better!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM