0

how are you? My excersize is to compare 3 clients with a boolean and i would like if my code is okay. Let me show my code. I just checked the ampscript guide but it isnt enough. Looks easy but i'vent any place to check my code. Thank you ! (it's for an email)

%%[
    var @clientA, @clientB, @clientC, @contentToShow
    set @clientA = AttributeValue("SubscriberA");
    set @clientB = AttributeValue("SubscriberB");
    set @clientC = AttributeValue("SubscriberC");

    if (@clientA == true) and (@clientB == true) and (@clientC == true) then
        set @contentToShow = "hello"
    elseif (@clientA == false) and (@clientB == true) and (@clientC == false) then
        set @contentToShow = "hola"
    else (@clientA == false) and (@clientB == false) and (@clientC == false) then
        set @contentToShow = "hallo"
    endif

]%%

%%v=(@contentToShow)=%%
0

Your else cannot come with a condition. Make your else an elseif statement and include an else statement without a condition to display a default case.

%%[
    var @clientA, @clientB, @clientC, @contentToShow
    set @clientA = AttributeValue("SubscriberA");
    set @clientB = AttributeValue("SubscriberB");
    set @clientC = AttributeValue("SubscriberC");

    if (@clientA == true) and (@clientB == true) and (@clientC == true) then
        set @contentToShow = "hello"
    elseif (@clientA == false) and (@clientB == true) and (@clientC == false) then
        set @contentToShow = "hola"
    elseif (@clientA == false) and (@clientB == false) and (@clientC == false) then
        set @contentToShow = "hallo"
    else
        set @contentToShow = "helloFallback"
    endif

]%%

%%v=(@contentToShow)=%%

You can leave the else part if you like. Or you can make one of the elseif statements (the last one in the order) to an else without a condition

| improve this answer | |
0

If you are looking for the output of boolean true, then you actually do not need to put a comparison in your conditionals as it will already resolve to the value of true.

To that vein, you can shorten your conditions a bit.

%%[
    var @clientA, @clientB, @clientC, @contentToShow
    set @clientA = AttributeValue("SubscriberA");
    set @clientB = AttributeValue("SubscriberB");
    set @clientC = AttributeValue("SubscriberC");

    set @contentToShow = "hallo"

    if @clientA and @clientB and @clientC then
        set @contentToShow = "hello"
    elseif @clientA and @clientB and NOT(@clientC) then
        set @contentToShow = "hola"
    endif

]%%

%%v=(@contentToShow)=%%

As you may have noticed, I also removed the final 'else' condition. I am assuming you meant this as a 'catch-all' default if it does not meet any of the other conditions. To help save space, I set it to this value above the if conditions so that the default is set and if none of the conditions are true, then the value remains at the original set value.

This is not a huge difference in processing or anything, at most it saves you a line of code and 4 characters, but I have seen it used more and more often as many think it is more 'readable' and easier to maintain.

| 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.