I'm new with AMPscript. I'm trying to make my AMPscript look better
Original script:

var @pointsBalance, @memberLevel
set @pointsBalance = AttributeValue("Total")
if @pointsBalance > 1000 then
    set @memberLevel = "VIP"
elseif  500< @pointsBalance and @pointsBalance <=1000 then
    set @memberLevel = "Gold"
    set @memberLevel = "Standard"

<p>You are a valued %%=v(@memberLevel)=%% member.<p>

I expected something like:


That means we just need to write the script in one line.

One more question. At first in the second condition I wrote

elseif  500< @pointsBalance <=1000 then

And it didn't work. Any suggestions to make the code better? Thank you in advance.

  • For your first question you've provided your expected output, but what are you getting instead? Is there an error? – nbrown Jun 2 '20 at 15:34

I dont know if this is any worth it... but if you really would like nested functions i would go like this:

IIf(@pointsbalance>=1000, "VIP", IIF(@pointsbalance>500,"Gold","Standard"))

Becoming this

<p>You are a valued %%=IIf(@pointsbalance>=1000, "VIP", IIF(@pointsbalance>500,"Gold","Standard"))=%% member.<p>


<p>You are a valued %%=v(IIf(@pointsbalance>=1000, "VIP", IIF(@pointsbalance>500,"Gold","Standard")))=%% member.<p>

but i believe the v() function can be left out.

  • Thanks Johan. I just realized that nested functions made the code hard to review. But it's really nice to know the way to do it :) – duyduc27 Jun 9 '20 at 1:56

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.