1

I would like to make the following scenario work somehow:

  1. I have a template that contains a script inside. The script defines a variable called X and sets it value to 1.
  2. I also have a content block containing a script that reads the value of variable X does some action with it and then increments its value.
  3. Finally I have an email that is based on the template and contains two instances of the content block.

    My expectation for this scenario is that when the first block reads the value of X it will get 1 and then the second block will get 2. But unfortunately it is not the case, both blocks read X as 1.

    The question is if it is possible somehow to make this scenario work the way I expect.

    Script in the template:

    %%[

    set @x = 1

    ]%%

    Script in the content block:

    %%[

    set @current_x = @x

    /* Do some stuff with @current_x */

    set @x = @x + 1

    ]%%

Thanks, Peter

  • 1
    Can you put sample amp code for more visualization of the issue you are facing – Avijit Chakraborty Jul 5 '17 at 16:12
  • I have just added two simple code snippets to make it clear what I need. When I put two instances of the content block below each other , and when the blocks are evaluated I expect that current_x should be 1 for the first instance and current_x should be 2 for the second instance. – Peter Neumann Jul 6 '17 at 7:38
  • Could you declare @x explicitly, please? "VAR @x... SET @x = 1..." and then use the ADD function when incrementing "SET @x = ADD(@x,1)". – Macca Jul 6 '17 at 8:02
  • @AndrewMcLeod Changed the code the way you suggested but the result is the same. X is still read as 1 by both instances. – Peter Neumann Jul 6 '17 at 11:39
0

You can achieve this by setting the same variable name with the Add() function.

AMPscript

%%[

set @x = 1

]%%

Value of @x = %%=v(@x)=%%<br/>

%%[

set @x = Add(@x, 1)

]%%

Value of @x = %%=v(@x)=%%<br/>

%%[

set @x = Add(@x, 1)

]%%

Value of @x = %%=v(@x)=%%<br/>

This results in the following

Value of @x = 1
Value of @x = 2
Value of @x = 3

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.