0

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"
else
    set @memberLevel = "Standard"
endif
]%%

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

I expected something like:

https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/iif.htm

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.

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

1 Answer 1

1

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>

or

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

1
  • 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 :) Commented Jun 9, 2020 at 1:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.