0

I am building an email in Content Builder that will show GTL variables but I want to set an AMPscript variable to the target Data Extension’s name. I find that I can use AMPscript variables in the GTL dataobject filter but when I preview the email I get an error when doing the same in the dataobject target. I have tried the code bellow but it tries to search a Data Extension named @target_DE.

%%[

VAR @target_DE
SET @target_DE = "DE_name"

]%%

{{.dataobject Name type=list maxRows=10}}
{{.data}} 
{
    "target" : "@target_DE",
    "filter" : "NewsLanguage == @Language && Version == @Version"                             
}                                  
{{/data}}                                  
{{/dataobject}}    

If it is written without “” ("target" : @target_DE) I get an error while parsing the value because of the @ character.

I have also tried embeding the dataobject type list in another dataobject of type variable as in the code bellow, but get an error when parsing the json (it says the item is not an object but a String).

%%[
VAR @target_DE
SET @target_DE = "{"DE":"DE_name"}" 
]%%
                  
{{.dataobject DataExtension type=variable source=@target_DE maxrows=1}}
                  
{{.data}}
       "target" : "@target_DE"           
{{/data}}
{{/dataobject}}                  
        
{{#DataExtension}}
                  
{{.dataobject Header_Footer type=list maxRows=10}}
{{.data}} 
{
    "target" : {{DE}},
    "filter" : "NewsLanguage == @Language && Version == @Version"                             
}                                  
{{/data}}                                  
{{/dataobject}}           
          
(html code goes here)

{{/DataExtension}}

The idea is that non technical people can change de Data Extension name in the AMPscript code block that will appear at the begining of the email without editing the GTL code block. Have you accomplished something of the like? Can you help me to find a solution for my need? Thank you. Regards

0

You can do something like this, when Header_Footer target is the name of the DataExtension from where you want to load:

%%[
  SET @TargetDE = 'NameOfTheDataExtension'
]%%
{{.dataobject Header_Footer type=list maxRows = 10}}
    {{.data}}
        {
           "target" : "name:[@TargetDE]",
           "filter" : "NewsLanguage == @Language && Version == @Version"  
        },            
    {{/data}}
{{/dataobject}}
| improve this answer | |

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.