Programmatic Languages
You will be challenged to:
- Demonstrate knowledge of AMPscript and SSJS language syntax and functions.
- Implement standard development best practices using Marketing Cloud programming languages
- Describe how Marketing Cloud handles AMPscript processing.
- Determine how to programmatically exclude a subscriber at email send time
AMPscript
Functions
- IIF() - IF statement inline
- Output() - Enables variable values to be output at the location where the code block appears. Useful for debugging.
- Encryption
- Encoding
- Data Extension Functions
- InsertData()
- LookupRows() - Returns a rowset with limit of 2,000 rows
- LookupOrderedRows() - Returns specific number of rows and has the ability to sort rows. (2,000 is default)
- Lookup() - gives you 1 value/cell from a data extension
- !!! - The majority of the AMPscript questions will likely be around interacting with Data Extensions, so be very familiar with them
- !!! - Important to understand the difference between LookupRows() and Lookup()
- !!! - Important to understand the difference of LookupRows() and LookupOrderedRows()
- Math Functions
- String Functions
- Date/Time Functions
- !!! - Uses server time
- Now() - Central Standard Time (CST) without daylight saving time.
- DateAdd()
- DateDiff()
- DateParse()
- DatePart()
- FormatDate()
- SystemDateToLocalDate()
- Content Functions
-
MobileConnect Funtions
-
Other Functions
- BeginImpressionRegion()
- EndImpressionRegion()
- !!! - RaiseError() - Stops the execution of send
- FormatCurrency()
- Not - Reverses the Boolean expression - E.g. not Empty(theField)
- AttributeValue()
- GUID()
- Empty()
- Format()
- Row()
- RowCount() - E.g. combine with IF statement to show default content
- Field()
- Output()
- HTTP Functions
- HTTPGet()
- RedirectTo()
- HTTPPost()
- !!! - To basically work with external data
- SFDC Functions
- RetrieveSalesforceObjects() - Creates a record in a Salesforce object
- Site-Based Functions
- CloudPagesURL()
- RequestParameter() - used on CloudPages
- QueryParameter()
- API Functions
- Data Modification Functions
Syntax
- Attributes
- Use [] square brackets to refer to attributes that contain space in the name (E.g. Data Extension Fields)
- VAR
- Used to declare a variable
- Tells the system that the variable exists
- Declared variables get the value of NULL
- !!! - Variable declaration VAR @variable is considered a best practice, even though is not mandatory
- SET
- Assign a value to a decalred variable
- AMPScript is case INsensitive
- The platform ignore the case (lower,upper)
- @firstname is the same as @firstNAME or @FIRSTname
- Delimiters
- Block: %%[ some code here ]%%
- Inline: %%=SomeFunctionHere=%%
- Comparison
- Is equal: ==
- Is not equal: !=
- Greater than: >
- Less than: <
- Greater or equal than: >=
- Less than or equal than: <=
- AND: Both conditions must be true
- OR: Either condition must be true
- NOT: The opposite value of a boolean expression
- Conditional Logic
- Process Loop: FOR ... TO ... DO ... NEXT
- Evaluate conditions: IF ... ELSEIF ... ELSE ... ENDIF
- Commenting
- /* comment */
SSJS
Platform Functions
Platform Server-side JavaScript functions allow you to use standard JSON and JavaScript functionality to interact with the Marketing Cloud platform. Platform objects can function within email messages, mobile messages, CloudPages, microsites, and landing pages. Because platform objects exist outside of the core library, you can realize faster performance than with other Server-side JavaScript functions.
- SMS
Core Functions
Core library server-side JavaScript functions allow you to use standard JSON and JavaScript functionality to interact with Marketing Cloud. Core objects can function within landing pages and applications.
- Landing Pages
- Applications
Things to Know
SSJS Methods
- Add — Invokes the web service API Create method on an API object
- Remove — Invokes the web service API Delete method on an API object
- Update — Invokes the web service API Update method on an API object
- Retrieve — Invokes the web service API Retrieve method on an API object
SSJS Call Parameters
- Language, ExecutionContextType, ExecutionContentName
- Language parameter, you can specify either JavaScript or AMPscript. The system defaults to JavaScript.
- For ExecutionContextType, you can specify either Get or Post. If no parameter is specified, the system defaults to Get.
- For ExecutionContextName
SSJS Supported Personalization String Tags
- ctrl:field — References subscriber attribute values, system attribute values, and sendable data extension field values
- ctrl:var — References variables created in AMPscript or server-side JavaScript script blocks
- ctrl:eval — Embeds JavaScript expressions as content substitutions
Parse JSON (Platform)
HTTP Functions (Core)
Data Extension Functions (Platform)
- LookUp()
- LookUpRows()
- LookUpOrderedRows()
- UpdateDE() - Email Only
- UpsertDE() - Email Only
- UpdateData() - Non-sendable context
- UpsertData() - Non-sendable context
AMPscript Variable Functions (Platform)
- GetValue() - var example = Platform.Variable.GetValue("@AMPscriptValue");
- SetValue() - Platform.Variable.SetValue("@exampleVariable","exampleValue");
Personalization Strings
- Is not AMPScript
- Used to insert account/subscriber specific values from
- Profile attribute
- Data Extension column
- Can be used
- Inside AMPscript: Does not use %%...%%
- Outside AMPscript: Used with %%...%%
- _messagecontext
- _IsTestSend: Resolves to TRUE if the email job is marked as a Test Send.
Exclusion Scripts
Where it can be found
How it works
- It excludes subscribers at the send time
- No AMPScript blocks or Inline AMPScript can be included
- Variables cannot be set
- The expression must return TRUE or FALSE
- The script cannot spread to multiple lines
Uses AMPScript expressions
- If evaluated to TRUE, then suppress the particular sending
Sample Use Case
- API triggered send with no possibility to deduplicate the send
- For instance, welcome email that is meant to be sent only once
- For instance, exclude some domain: Domain(emailaddr) != "yahootest.com"
Best practices
- Try to avoid it
- Treat your exclusions during the segmentation
How to use AMPScript & SSJS together
- Set Variable
- Variable.SetValue("myVariable","myValue");
- Get Variable
- Variable.GetValue("@myAmpVariable");
Error Handling
<script runat="server">
Platform.Load('Core','1');
try {
</script>
%%[ AMPScript Code ]%%
<script runat="server">
} catch(e) {
Write(Stringify(e));
}
</script>
Recommendation Where to use what
- AMPScript
- Emails and Landing pages
- SSJS
- Landing pages and Script activities
- GTL
- Emails: Especially to standardize presentation layer (E.g. Transactional Messages)
Email Order of Execution
- Preheader
- HTML Boday
- Text Body
- Subject Line