2

I am super new to the forum and new to AMPscript as well, so sorry if there's some imprecision in my question. :-)

I am trying to build some Dynamic Content for an email. I have 3 dynamic content blocks in total. The data for 2 of the blocks is contained in the same DE I will be using for the send out (A), and it works properly. I am having issues with the third block, which should use data located in another data extension (B - non-sendable). If I remove the third block (IF statement), then I do not get any error messages.

The logic is very simple and it's the same for all three blocks. If a = b, show content block x. If not, show content block y.

I know that B is NOT connected to the Main DE "Contacts" in Audience Builder. Also, "Hvilken_type_bolig" is not a boleean, while "Mode" and "Winner" are. Could that be the issue? Or is there a problem with my code?

Thank you and cheers :)

EDIT: The record I am trying to generate a Subscriber Preview with exists in all the above-mentioned DEs (Contacts, A, B) with the same SubscriberKey.

Error code:

An error occurred when attempting to parse HtmlEmailBody content for HTML content. MemberID: 100009251 JobID: 0 ListID: 0 Content Begins With: {{.block g432s5hg96 codesnippetblock}}{{.data}}{ "email": { "options": { "generateFro

Code:

%%[ Var @Winner, @SubscriberKey 
Set @SubscriberKey = Lookup('Contacts','SubscriberKey','SubscriberKey', @SubscriberKey), 
Set @Winner = Lookup('A','Winner','SubscriberKey', @SubscriberKey)

%%[ Var @Create_Lead, @SubscriberKey 
Set @SubscriberKey = Lookup('Contacts','SubscriberKey','SubscriberKey', @SubscriberKey),
Set @Create_Lead = Lookup('A','Create_Lead','SubscriberKey', @SubscriberKey)

%%[ Var @Hvilken_type_bolig, @SubscriberKey 
Set @SubscriberKey = Lookup('Contacts','SubscriberKey','SubscriberKey', @SubscriberKey),
Set @Hvilken_type_bolig = Lookup('B','Hvilken_type_bolig','SubscriberKey', @SubscriberKey)

%%[IF (([Winner] == "True")) THEN]%% %%=ContentBlockById("1832577")=%% %%[ELSE]%% %%=ContentBlockById("1832580")=%%%%[ENDIF]%%
%%[IF (([Create_Lead] == "True")) THEN]%% %%=ContentBlockById("1836190")=%% %%[ELSE]%% %%=ContentBlockById("1836192")=%%%%[ENDIF]%%
%%[IF (([Hvilken_type_bolig] == "Andelsbolig")) THEN]%% %%=ContentBlockById("1836189")=%% %%[ELSE]%% %%=ContentBlockById("1836193")=%%%%[ENDIF]%%

1
  • I believe you said Hvilken_type_bolig is from a separate DE and not on the sendable data. If that is the case you need to change IF (([Hvilken_type_bolig] == "Andelsbolig")) to IF ((@Hvilken_type_bolig == "Andelsbolig")) as you are using the variable you set above and not a field from the sendable data. If this field does not exist and you do not use AttributeValue() then it will throw an error. Usually a different error, but that might still be the problem. Also do not need the parenthesis around the if statements Aug 31, 2022 at 13:19

2 Answers 2

2

Just in case my comment is correct, I wanted to move it to an answer so it is clearer:

You are referencing Hvilken_type_bolig as a field from your sendable data (the data source you attached to the send) and from what you mentioned previously, this is not a field on there. You are retrieving it from a relational DE.

I see the setting of a variable of the same name prior to your conditional statements, so I think the major issue is that [Hvilken_type_bolig] should instead be @Hvilken_type_bolig.

There were some other not necessarily 'wrong' aspects to your code, but parts that can be optimized, which I did below for a final example.

%%[  
Set @SubscriberKey = AttributeValue("_subscriberkey") 
/* There is no need to do a lookup, the Subscriberkey is automatically a field you can grab */ 

/* Could probably do a lookuprows instead of two lookups here, but this works as well*/
Set @Winner = Lookup('A','Winner','SubscriberKey', @SubscriberKey)
Set @Create_Lead = Lookup('A','Create_Lead','SubscriberKey', @SubscriberKey)

Set @Hvilken_type_bolig = Lookup('B','Hvilken_type_bolig','SubscriberKey', @SubscriberKey)
]%%

%%[IF @Winner == "True" THEN]%% 
  %%=ContentBlockById("1832577")=%% 
%%[ELSE]%% 
  %%=ContentBlockById("1832580")=%%
%%[ENDIF]%%

%%[IF @Create_Lead == "True" THEN]%% 
  %%=ContentBlockById("1836190")=%% 
%%[ELSE]%% 
  %%=ContentBlockById("1836192")=%%
%%[ENDIF]%%

%%[IF @Hvilken_type_bolig == "Andelsbolig" THEN]%% 
  %%=ContentBlockById("1836189")=%% 
%%[ELSE]%% 
  %%=ContentBlockById("1836193")=%%
%%[ENDIF]%%
1
  • Adding "@" in the if statement fixed it for me. Thank you for the comments on the other parts of the code! Super helpful to understand the logic better. :-)
    – orsetto
    Aug 31, 2022 at 14:10
2

Try this:

%%[
Set @SubscriberKey = AttributeValue("SubscriberKey")
Set @Winner = Lookup('A','Winner','SubscriberKey', @SubscriberKey)
Set @Create_Lead = Lookup('A','Create_Lead','SubscriberKey', @SubscriberKey)
Set @Hvilken_type_bolig = Lookup('B','Hvilken_type_bolig','SubscriberKey', @SubscriberKey)

IF @Winner == "True" THEN]%% 
%%=ContentBlockById("1832577")=%% 
%%[ELSE]%% 
%%=ContentBlockById("1832580")=%%
%%[ENDIF]%%

%%[IF @Create_Lead == "True" THEN]%% 
%%=ContentBlockById("1836190")=%% 
%%[ELSE]%% 
%%=ContentBlockById("1836192")=%%
%%[ENDIF]%%

%%[IF @Hvilken_type_bolig == "Andelsbolig" THEN]%% 
%%=ContentBlockById("1836189")=%% 
%%[ELSE]%% 
%%=ContentBlockById("1836193")=%%
%%[ENDIF]%%

Here's a couple of issues you had in your script:

  1. The SubscriberKey variable was set to do a lookup based on the SubscriberKey variable, which essentially wouldn't work. I have set it to take the SubscriberKey from the SubscriberKey attribute in your Sendable DE. If the SubscriberKey field is called something else in your sendable DE, please change the name inside the AttributeValue function.

  2. You had some AMPscript blocks that were not closed with a ]%%

  3. In the conditional statements, you forgot to include the @ symbol at the beginning of the variable names.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .