Friday, February 9, 2018

SalesForce Marketing Cloud - Ampscript

Hi All

Below I have added simple coupon code implementation using ampscript.


Some important points to note:


  1. I have the messagecontext as preview - when sending it should be send
  2. My data extension is called Coupons ( this should be replaced with your own if needed)
  3. This is merely a skeleton and you can write so much more to the data extension :-)


 %%[
var @em, @couponRow, @couponCode
if _messagecontext == "PREVIEW" then
set @couponCode = "XX TEST XX"

else
/* include your sendable attribute/column here */
set @em = AttributeValue("emailAddr")

set @couponRow = ClaimRow("Coupons", "IsClaimed", "EmailAddress", @em)

if empty(@couponRow) then

/* You can do other error handling here if you want.*/
/* This aborts the send */
RaiseError("No coupons available", false)

else
SET @couponCode = Field(@couponRow, "CouponCode")
endif

endif
]%%

Here's your coupon code: %%=v(@couponCode)=%%


My the force be with you.

Kind Regards
Jerome

No comments:

Post a Comment

Generate reports from Opportunities using a Visualforce Page in Salesforce

  Step 1: Create a Visualforce Page Go to the Setup menu in Salesforce. Search for "Visualforce Pages" in the Quick Find box and c...