3

I have to call the variable @xyz inside an AMPScript block and it throws errors when I try to call it like %%=v(@xyz)=%% This is something I need almost on a daily basis and I still couldn't find something to work for me. How do you do this?

e.g.

%%[

Var @abc, @xyz, @123

Set @abc = [ABC]
Set @xyz = [XYZ]

IF @abc == 'y' THEN
  Set @123 = 'This is variable %%=v(@xyz)=%%'
ENDIF

]%%
  • Concat won't work in my case since I have to add entire tables and not just words. – Snowalker Oct 7 '14 at 21:06
  • You can add html to your string. Using the example above - SET @123 = CONCAT("This is variable: <table><tr><td>",@xyz,"</td></tr></table>") – victorcorey Oct 9 '14 at 18:22
  • Why are you setting @123? That doesn't actually make sense to me. – Kelly J Andrews Oct 9 '14 at 20:18
  • it's because I'm calling @123 somewhere in the body of the email. – Snowalker Oct 11 '14 at 2:03
  • I think something maybe over complicated here, but to clarify, you want to set (@)123 to render (@)xyz somewhere in the email, correct? – Kelly J Andrews Oct 11 '14 at 16:07
1

Perhaps something like this?

%%[

    Var @abc, @xyz

    Set @abc = [ABC]
    Set @xyz = [XYZ]

    IF @abc == "y" THEN 
]%%
<table>
    <tr>
        <td>This is variable %%=v(@xyz)=%%</td>
    </tr>
</table>
%%[ ENDIF ]%%

I have some other examples on my blog that are specific for iterating through result-sets, but you may find some of the conditional structures helpful.

EDIT:

An example with @123

%%[

    Var @abc, @xyz, @123

    Set @abc = [ABC]
    Set @xyz = [XYZ]
    Set @123 = ""

    IF @abc == "y" THEN 
       set @123 = concat("This is variable: ",@xyz)
]%%
<table>
    <tr>
        <td>%%=v(@123)=%%</td>
    </tr>
</table>
%%[ ENDIF ]%%
| improve this answer | |
  • Thanks Adam but how do you assign the value to @123 ? – Snowalker Oct 8 '14 at 12:44
  • Updated my example above. – Adam Spriggs Oct 8 '14 at 15:25
  • Also, I don't think you can have an AMPScript variable that starts with a number. I may be wrong in that -- regardless, it's not a good practice. – Adam Spriggs Oct 8 '14 at 15:26
  • Variable names must begin with the @ symbol and be followed by at least one other letter, number, or underscore. – victorcorey Oct 9 '14 at 18:19
  • you can start a variable with _ e.g. _123 – Snowalker Oct 11 '14 at 2:03
0

Thanks guys but the Output(@xyz) function is printing "Output(@xyz)' instead of the value of @xyz. I also tried calling it simple as @xyz and again, is printing "@xyz" instead of the value. Do I do anything wrong? Thanks for helping :) Vic

| improve this answer | |
0

You have already opened up the AMPScript block %%[ ]%% so you can't use %%==%% inside it.

If you wish to output the variable inside the AMPScript block, use the Output() function (%%=v()=%% is used for inline output).

If you want to set a variable to a string and a variable together, use Concat():

Set @123 == Concat('This is variable ', @xyz)

| improve this answer | |
0
%%[
OutputLine(V('Print Testing in progress'))
]%%

%%[var @test
SET @test = "Success!!!"
OutputLine(V(@test))
]%%

Ref: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/output.htm

| improve this answer | |
  • please include the essentials of the link, not just the link (such as why the code you provided works) – glls May 17 '18 at 3:08

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.