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

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.

  • Email
  • 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)

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

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

  1. Preheader
  2. HTML Boday
  3. Text Body
  4. Subject Line

Resources