#1- The Ampscript Syntax

Ampscript is one of the language of Salesforce Marketing Cloud. Ampscript runs on the servers of Salesforce Marketing Cloud. The code is embedded in the HTML emails, email text messages, landing pages, mobile phone messages, mobile app push notifications.

The code is rendered from top to bottom. What I mean is, it is an interpreted language. We do not need any special compiler to run it.

I mostly use it for email or any Salesforce Marketing Cloud message personalization. To create a personalized message, the Ampscript code needs to be interacting with the data model in the marketing cloud. The data mostly recorded in the Data Extensions of Marketing Cloud. In some case, the data may be in lists, or comes with json payloads thru an API interaction. In my following articles, I will give more information on how to interact with data.

When using Ampscript as Ampscript Block, the code is written between double percentage and squared brackets( %%[ ]%% )

This is an simple syntax of an Ampscript Block:


 var @firstName 
 var @lastName 
 set @firstName = "Mustafa"
 set @lastName = "Unlukara"


The Ampscript code, when used in HTML (inline) is written in double percentage chars (%%).

Here is an simple example:

Dear %%=v(@firstName)=%%  %%=v(@lastName)=%%,<br />Thank you for choosing our company as your service provider.

You can also write your Ampscript code within and SSJS (Server Side Javascript) code.

Here is the syntax for it:

<script runat="server" language="ampscript"> 

/* Write your Ampscript code here.  */ 


Dynamical Personalization with Ampscript

Ampscript is a very easy way to personalize emails dynamically in Salesforce Marketing Cloud.

When you have a “Sendable Data Extension”, we are able to populate the data in the fields by adding fieldname between double percentage (%%) signs.

Here is an example;

Let’s say our Sendable DataExtension contains the following records.

CustomerIDFirstName LastNameEmailAddress

We want to start emails with the following format,

Dear FirstName,

In our data extension, we do not have Proper case for values. Some first name values are missing.

We need to send First names in a proper case, and for the missing values we need to use “Valued Customer” text, instead of sending emails with missing first name.

Here is the Ampscript solution code of the personalization ampscript.

Ampscript Personalization Code

“Valued Customer” is added by IIF statement when the first name value of the customer record is missing.