Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

salesforce - Use string as variable name in AMPScript

I have the following problem with Salesforce' AMPScript in Marketing Cloud:

I have two variables, I want to combine a string and one of these variables to get the value of the other variable.

I have the variable @country_code and for example @translate_DE. If @country_code now has the value DE, how do I create the variable @translate_DE out of it? I already tried with CONCAT like this:

SET @translation_var = CONCAT('translation_',@country_code)

But this is only generating the string translation_DE, now I need this string as variable.

This is some code for testing, which makes it a little bit more clear:

<script runat="server" language="ampscript">
  var @country_codes, @country_code_list
  set @country_codes = 'AD,AE,AF,AG,AI,AL,AM,AN,AO,AQ,AR,AS,AT,AU,AW,AZ,BA,BB,BD,BE,BF,BG,BH,BI,BJ,BM,BN,BO,BR,BS,BT,BV,BW,BY,BZ,CA,CC,CD,CF,CG,CH,CI,CK,CL,CM,CN,CO,CR,CU,CV,CX,CY,CZ,DE,DJ,DK,DM,DO,DZ,EC,EE,EG,EH,ER,ES,ET,FI,FJ,FK,FM,FO,FR,GA,GD,GE,GF,GH,GI,GL,GM,GN,GP,GQ,GR,GS,GT,GU,GW,GY,HK,HM,HN,HR,HT,HU,ID,IE,IL,IN,IO,IQ,IR,IS,IT,JM,JO,JP,KE,KG,KH,KI,KM,KN,KP,KR,KW,KY,KZ,LA,LB,LC,LI,LK,LR,LS,LT,LU,LV,LY,MA,MC,MD,MG,MH,MK,ML,MM,MN,MO,MP,MQ,MR,MS,MT,MU,MV,MW,MX,MY,MZ,NA,NC,NE,NF,NG,NI,NL,NO,NP,NR,NU,NZ,OM,PA,PE,PF,PG,PH,PK,PL,PM,PN,PR,PS,PT,PW,PY,QA,RE,RO,RU,RW,SA,SB,SC,SD,SE,SG,SH,SI,SJ,SK,SL,SM,SN,SO,SR,ST,SV,SY,SZ,TC,TD,TF,TG,TH,TJ,TK,TM,TN,TO,TP,TR,TT,TV,TW,TZ,UA,UG,UK,US,UY,UZ,VA,VC,VE,VG,VI,VN,VU,WF,WS,YE,YT,YU,ZA,ZM,ZW'
  set @country_code_list = BuildRowsetFromString(@country_codes,',')

  set @translate_DE = 'Germany'
  set @translate_CH = 'Switzerland'
</script>

<!doctype html>
<html>
<head>
 <meta charset="utf-8">
 <title></title>
 <meta name="description" content="">
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
%%[ 
FOR @i = 1 TO Rowcount(@country_code_list) DO
  SET @row = Row(@country_code_list,@i)
  SET @country_code = Field(@row,1,0)
  SET @translation_var = CONCAT('translation_',@country_code)
]%%
%%=v(@country_code)=%%<br>
%%=v(@translation_var)=%% /* I want to output the value of @translation_DE and others here */<br><br>
%%[ NEXT @i ]%%
</body>
</html>```

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...