0

I have two amp script conditions in the email,

Condition1: (to show the content based on country code)

IF @CountryCode == "RU" THEN SET @CountryCode = "EN"
ELSEIF @CountryCode == "RO" THEN SET @CountryCode = "EN"

ELSEIF @CountryCode == "BE" AND @Language == "NL" THEN SET @CountryCode = "NL"
ELSEIF @CountryCode == "BE" AND @Language == "FR" THEN SET @CountryCode = "FR"
ELSEIF @CountryCode == "BE" AND (@Primary_Language__pc != "NL"
OR @Primary_Language__pc != "FR")
THEN SET @PersonMailingCountryCode = "FR"

Condition 2: (to display to preheader, footer details based on country code)

%%[
IF @Customer =='True' 
AND (@CountryCode == 'BE'
AND @Language == 'fr')
THEN 
]%%


%%=ContentBlockById("123456")=%%

%%[
ELSEIF @Customer =='True'
AND (@CountryCode == 'BE'
AND @Langaugae == 'nl')
THEN 
]%%

%%=ContentBlockById("234567")=%% 

%%[
ENDIF
]%%


%%[
IF @Customer =='False' 
AND (@CountryCode == 'BE'
AND @Langauge == 'fr')
THEN 
]%%


%%=ContentBlockById("34567")=%% 

%%[
ELSEIF @Customer =='False'
AND (@CountryCode == 'BE'
AND @Language == 'nl')
THEN 
]%%

%%=ContentBlockById("45678")=%% 

%%[
ENDIF
]%%

%%[
IF @Customer =='True' 
AND (@CountryCode == 'BE'
AND @Language != 'fr'
AND @Language != 'nl')
THEN 
]%%

%%=ContentBlockById("56789")=%%

%%[
ELSEIF @Customer =='False' 
AND (@CountryCode == 'BE'
AND @Language != 'fr'
AND @Language != 'nl')
THEN 
]%%

%%=ContentBlockById("67890")=%%

%%[
ENDIF
]%%


%%[
IF @Customer =='True' 
AND @CountryCode != 'BE'

THEN 
]%%


%%=Contentblockbyname(Concat("Content Builder\Test\preheader_SFDC_",CountryCode),"",0,ContentBlockByName("Content Builder\Test\preheader_SFDC_",CountryCode_EN"))=%%

%%[
ELSEIF @Customer =='False'
AND @CountryCode != 'BE'
THEN 
]%%

%%=Contentblockbyname(Concat("Content Builder\Test\preheader_SFDC_",CountryCode),"",0,ContentBlockByName("Content Builder\Test\preheader_SFDC_EN"))=%%

%%[
ENDIF
]%%

When I use both conditions, my pre header, signature and footer ampscript changes to English automatically and body content reflect the content based on condition 1. when I use just condition 2, my pre header, signature and footer ampscript works as expected.

Can you please let me know what went wrong? It would be really helpful if anyone helps me find a way for this issue.

2
  • Can you confirm your Condition1: has an ENDIF at the end! Commented Apr 27, 2020 at 14:41
  • Yes, It has ENDIF Commented Apr 27, 2020 at 14:54

1 Answer 1

0

this is not an answer to your question "what went wrong", I'm not sure if this can be answered from the outside. But your code can be cleaned up quite a bit.

There are typos in codebit two, so it shouldn't be working - although you say the code works as expected. (e.g. "@Langaugae"), This line: %%=Contentblockbyname(Concat("Content Builder\Test\preheader_SFDC_",CountryCode),"",0,ContentBlockByName("Content Builder\Test\preheader_SFDC_",CountryCode_EN"))=%% is syntactically wrong.

I've gone ahead and restructured the code completely. It is not tested, and I cannot verify 100% it's correct. Think of it as a suggestion for code structure, not a complete solution.

I would encourage you to conceptualize your if / elses more. Your logic is completely flat (if x then y, elseif a then b ,... ). You can work a lot more with nested ifs, setting up a logical hierarchy of your checks. ("first I check customer status, then I check countryCode, then I check language"). Use indentation to visualize it.

This can shorten the code considerably and really helps to visually spot gaps in your logic. Also, use ELSEs. An if/else block without an ELSE risks logical gaps.

Also, get a code editor with syntax highlighting to spot syntax errors.

%%[
IF @countryCode == "BE" AND @language == "NL" THEN 
    SET @countryCode = "NL"
ELSEIF @countryCode == "BE" AND @language == "FR" THEN 
    SET @countryCode = "FR"
ELSEIF @countryCode == "BE" AND (@primary_Language__pc != "NL" OR @primary_Language__pc != "FR") THEN 
    SET @personMailingCountryCode = "FR"
ELSE /* RU / RO */
    SET @countryCode = "EN"
ENDIF 
]%%
%%[
IF @customer == 'True' THEN
    IF @countryCode == 'BE' THEN
        IF @language == 'fr' THEN 
            SET @id = "123456"
        ELSEIF @language == 'nl' THEN 
            SET @id = "234567"
        ELSE
            SET @id = "56789"
        ENDIF
        ]%%
        %%=ContentBlockById(@id)=%%
        %%[
    ELSE
        ]%%
        %%=Contentblockbyname(Concat("Content Builder\Test\preheader_SFDC_",CountryCode),"",0,ContentBlockByName("Content Builder\Test\preheader_SFDC_","CountryCode_EN"))=%%
        %%[
    ENDIF   
ELSE /* customer false or empty */
    IF @countryCode == 'BE' THEN
        IF @language == 'fr' THEN 
            SET @id = "34567"
        ELSEIF @language == 'nl' THEN 
            SET @id = "45678"
        ELSE
            SET @id = "67890"
        ENDIF
        ]%%
        %%=ContentBlockById(@id)=%%
        %%[
    ELSE 
        ]%%
        %%=Contentblockbyname(Concat("Content Builder\Test\preheader_SFDC_",CountryCode),"",0,ContentBlockByName("Content Builder\Test\preheader_SFDC_EN"))=%%
        %%[ 
    ENDIF
ENDIF
]%%

Hope this helps.

1
  • Your code completely makes sense and easier. I will give a try to your concept and keep you updated here. thank you Commented Jun 16, 2020 at 9:05

You must log in to answer this question.

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