1

I am currently using in email to call an image or link based on needs.

%%[IF Substring(ISO_CNTRY_2_CD,1,2) == "US" THEN]%%
<br><br>US<br><br>
%%[ELSE]%%
<br><br>CA<br><br>
%%[ENDIF]%%

This works great for just the two markets, but now need to do this for 4 markets. I have tried the following with no luck.

%%[IF Substring(ISO_CNTRY_2_CD,1,2) == "MX" THEN]%%
<br><br>Mexico<br><br>
%%[ELSEIF (ISO_CNTRY_2_CD,1,2) == "CL" THEN]%%
<br><br>Chile<br><br>
%%[ELSEIF (ISO_CNTRY_2_CD,1,2) == "CO" THEN]%%
<br><br>Colombia<br><br>
%%[ELSE (ISO_CNTRY_2_CD,1,2) == "AR" THEN]%%
<br><br>Argentina<br><br>
%%[ENDIF]%%
0

2 Answers 2

2

You're missing some substring() functions. I'd also recommend using the AttributeValue() function to retrieve the value for ISO_CNTRY_2_CD.

%%[
  var @isoCntry2Cd
  set @isoCntry2Cd = AttributeValue("ISO_CNTRY_2_CD")
]%%
%%[IF Substring(@isoCntry2Cd,1,2) == "MX" THEN]%%
<br><br>Mexico<br><br>
%%[ELSEIF Substring(@isoCntry2Cd,1,2) == "CL" THEN]%%
<br><br>Chile<br><br>
%%[ELSEIF Substring(@isoCntry2Cd,1,2) == "CO" THEN]%%
<br><br>Colombia<br><br>
%%[ELSE Substring(@isoCntry2Cd,1,2) == "AR" THEN]%%
<br><br>Argentina<br><br>
%%[ENDIF]%%
1
  • there's an extra @ in line 3 in the ampscript (i cannot edit as i need to edit 6 chars) :) Jun 23, 2017 at 7:42
0

Adams solution is spot on, i just want to add this reply in case your solution needs to scale across multiple markets - also, if for some reason you need to change the way you treat certain countries (imagine you want to replace all of the countries in south america, with "South America" in writing), you could make use of a mapping table (a de) and the lookuprows functionality instead. See below here for example:

%%[
  var @isoCntry2Cd, @CountryName, @CountryMapDE, @isoRow, @isoRows
  set @isoCntry2Cd = AttributeValue("ISO_CNTRY_2_CD")
  set @CountryMapDE = "CountryMappingDE"
  set @isoRows = LookupRows(@CountryMappingDE, "ISO_CNTRY_2_CD", @isoCntry2Cd)
  if rowcount(@isoRows) > 0 then
    set @isoRow = Row(@isoRows, 1)
    set @CountryName = Field(@isoRow, "CountryName")
  else
    set @CountryName = "Default text"
  endif
]%%
%%=v(@CountryName)=%%

You must log in to answer this question.

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