I want to store the variable name in a string and then evaluate the result. I have the following:

var @subscriber_key, @lookupFields, @first, @second, @rs

set @subscriber_key = AttributeValue("subscriber_key")
set @lookupFields = "subscriber_key;@subscriber_key"

IF IndexOf(@lookupFields, ";") > 0 THEN
    SET @rs = BuildRowsetFromString(@lookupFields,';')
    SET @first = Field(Row(@rs,1),1)
    SET @second = Field(Row(@rs,2),1)


First: %%=v(@first)=%%
Second: %%=v(@second)=%%

Will return:

First: subscriber_key
Second: @subscriber_key

Which is technically correct but what i want is @subscriber_key to be evaluated as well.

I tried

Second: %%=v(@=v(@second)=)=%%

but this returned empty string. If the variable @second holds the variable name of the variable i want to call, how do get that value. For example; the value of %%=v(@subscriber_key)=%% should be subscriber_1234. So i want that to be returned when i get the value for @second; the key here is that it may not always be subscriber_key or a variable that i know of so i am trying to indirectly reference and evaluate the variable stored in the string.



You must use the concat function to build your lookupFields, like this:

set @lookupFields = Concat("subscriber_key;",@subscriber_key)

In your code, the complete content of lookupFields is treated as a single string.

  • i cannot enter code there :( – Johannes Schapdick Nov 10 '20 at 7:46
  • See my edit comment, @JohannesSchapdick :-) Never check SFSE before coffee in the morning – Lukas Lunow Nov 10 '20 at 7:49

Your Answer

