SFMC AMPscript IF ELSE Use Cases
First Create a DE with the fields and records as per the use case:
Field Name includes- FirstName, LoyaltyStatus, Country
Use Case 1: Personalized Greetings
Go to Email Studio> Content> Create New Email> Select Blank Page Template
Use Code:
%%[
SET @FirstName = AttributeValue("FirstName")
IF NOT EMPTY(@FirstName) THEN
]%%
HELLO %%=V(@FirstName)=%%,
%%[
ELSE
]%%
Hello Customer,
%%[
ENDIF
]%%
When you use code, always ensure the Attribute value is defined correctly or else the personalisation will not be updated correctly.
If the DE does not have the Contact First name, you will see "Hello Customer"
If the first name is defined, you will see "Hello Raj,"
Use Case 2: Loyalty Offer
In continuation to the previous coding, I added the code for the loyalty offer. (Refer to the bold letters code). Add the Attribute Value and the code.
%%[
SET @FirstName = AttributeValue("FirstName")
SET @LoyaltyStatus = AttributeValue("LoyaltyStatus")
%%]
%%[IF NOT EMPTY(@FirstName) THEN
]%%
Hello %%=V(@FirstName)=%%,
%%[ELSE]%%
Hello Customer,
%%[ENDIF]%%
%%[If @loyaltyStatus == "Gold" THEN]%%
VIP Discount
%%[Else]%%
Regular Discount
%%[ENDIF]%%
Use Case 3: Country Based
%%[
SET @Country = AttributeValue("Country")
%%]
%%[If @Country == "India" THEN]%%
Free Shipping
%%[Else]%%
International Shipping
%%[ENDIF]%%
Comments
Post a Comment