---
schema_version: "1"
id: caaf8629218719573d17d3a0eb36c848c25d252aed52444b2afda22fa88335f4
title: SSJS Syntax Guide
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/guides/mc-programmatic-content/ssjs_syntaxGuide.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_syntaxGuide.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a25de39c2c6b5c6003db81b874bceab7f26569fa5f421069319928f909ca0481
products:
  - Marketing Cloud Engagement APIs and Programmatic Languages
  - Marketing Cloud
---
# SSJS Syntax Guide

Use the information in this document to correctly form SSJS function calls, declare variables and values, and reference keywords.

## Declare a Server-Side JavaScript Block

Use Script tags to delineate JavaScript blocks. These tags are processed as case-insensitive instances. Quotation marks are optional unless they're necessary to distinguish a value.

Marketing Cloud Engagement executes SSJS at the time the content is rendered.

When you use SSJS, you must specify that the code is run at the server, as shown in this example. If you don't specify this parameter, the browser tries to execute it, which results in errors.

```javascript
<script runat="server">[Add your SSJS code here]</script>
```

You can also specify additional parameters.

```javascript
<script
  runat="server"
  language="JavaScript"
  executioncontexttype="Post"
  executioncontextname="test"
>
  [Add your SSJS code here]
</script>
```

For the `Language` parameter, you can specify either `JavaScript` or `AMPscript`. The default value is JavaScript.

For `ExecutionContextType`, you can specify either `Get` or `Post`. The default value is `Get`.

For `ExecutionContextName`, you can specify a named context to execute.

## Personalization Strings

SSJS uses personalization tokens for subscriber and system attributes, data extension fields, variables, functions, and JavaScript code expressions.

### Supported Personalization String Tags

Use these tags as part of your personalization strings:

- `ctrl:field` - References subscriber attribute values, system attribute values, and sendable data extension field values.
- `ctrl:var` - References SSJS or AMPscript variables.
- `ctrl:eval` - Embeds JavaScript expressions as content substitutions.

### Supported Attributes

You can include these attributes in your personalization strings:

- `name` - Identifies the attribute, sendable data extension field, or variable. Include this value for all attribute and variable data sources.
- `default` - Provides an optional default value for all tags. The expression returns this value if the data source is null or an empty string.
- `format` - Specifies a format for the personalization string. SSJS supports standard .NET numeric and datetime strings.
- `language` - Specifies the language of the expression. Accepted values are `javascript` and `ampscript`. The default value is `javascript`.

### Syntax Samples

Use these examples as models for constructing your own SSJS code. Use this code anywhere in a landing page to provide personalized information.

#### Accessing an Attribute Name

Use the `ctrl:field` tag to reference subscriber information or information from a sendable data extension.

```
<ctrl:field name="AttributeName" />
```

You can optionally include the `default` parameter to specify a default value.

```
<ctrl:field name=AttributeName default="Default Value" />
```

#### Accessing a Variable

Access an SSJS variable by specifying its name.

```
<ctrl:var name="JSVar" />
```

To access an AMPscript variable, include the at sign (@) in the variable name.

```
<ctrl:var name=@AmpVar />
```

You can include the `default` attribute to provide a value if the variable is not found. You can also include the `format` variable to apply a format to the value of the variable.

```
<ctrl:var name="CurrentSpend" default="0" format="C" />
```

#### Evaluating an Expression

Use the `ctrl:eval` tag to evaluate a JavaScript expression.

```
<ctrl:eval>"a".toUpperCase() + "B".toLowerCase()</ctrl:eval>
```

You can use full-function syntax or the equivalent simple expression syntax. For example, both of these expressions produce the same result.

```
return "B".toUpperCase();
```

```
"B".toUpperCase()
```

## Platform Object Support for SSJS

SSJS interacts with information from Marketing Cloud Engagement by using libraries that are unique to SSJS. To use these libraries in your code, use the `Platform.Load()` function to load them.

```
Platform.Load("Core","1");
```

## Methods

SSJS supports these 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

## Code Access Security

SSJS can only access the .NET CLR (Common Language Runtime) objects exposed through the outlined libraries. Attempts to access disallowed CLR objects result in an error.
