DocumentationCampaignCampaign Web User Interface

Work with JavaScript codes

Last update: Fri Apr 11 2025 00:00:00 GMT+0000 (Coordinated Universal Time)
  • Applies to:
  • Campaign v8 Web User Interface

About JavaScript codes

JavaScript codes allow you to create reusable functions that can be used across workflows, similar to a library. These functions are stored in the Administration > JavaScript codes menu in the left navigation pane.

JavaScript codes list interface showing available options

From the JavaScript codes list, you can:

  • Duplicate or delete a code: Click the ellipsis button, and select the desired action.
  • Modify a code: Click a code’s name to open its properties, make your changes, and save.
  • Create a new JavaScript code: Click the Create JavaScript code button.
NOTE
Although the JavaScript codes menu location differs between the Adobe Campaign console and Web user interface, the list is identical and operates like a mirror.

Create a JavaScript code

To create a JavaScript code, follow these steps:

  1. Navigate to the JavaScript codes menu, and click the Create JavaScript code button.

  2. Define the code’s properties:

    • Namespace: Specify the namespace relevant to your custom resources. By default, the namespace is “cus”, but it may vary depending on your implementation.
    • Name: The unique identifier used to reference the code.
    • Label: The descriptive label displayed in the JavaScript codes list.

    JavaScript code creation interface showing namespace, name, and label fields

    NOTE
    Once created, the Namespace and Name fields cannot be modified. To make changes, duplicate the code and update as needed.
    In the Campaign console, the JavaScript code name appears as a concatenation of these two fields.
  3. Click the Create code button to define the JavaScript code. The left pane provides two menus that allow you to use predefined functions related to conditions and date formatting.

    JavaScript code editor interface showing predefined functions

  4. Click Confirm to save your code.

  5. When your JavaScript code is ready, click Create. The JavaScript code is now available for use across workflows.

Use a JavaScript code from a workflow

Load JavaScript code libraries

You can reference JavaScript codes in workflows to avoid rewriting code for repetitive tasks. To use these codes, load the corresponding library in the workflow’s initialization script. This allows you to load all the libraries containing the functions you want to use in your workflow once.

To load a library, follow these steps:

  1. Open a workflow, and click the Settings button.

  2. Navigate to the Initialization script section, and click Create code.

    Workflow initialization script interface showing code creation option

  3. Use the syntax below in the code to load a library:

    loadLibrary("/<namespace>/<name>")
    
    • Replace <namespace> with the namespace specified during the JavaScript code creation.
    • Replace <name> with the name of the JavaScript code.
  4. Click Confirm, and save the settings.

Reference functions in workflows

Once the JavaScript library is loaded, you can reference the functions defined in the JavaScript code directly within the workflow, typically using a JavaScript code activity.

Workflow interface showing JavaScript function usage

recommendation-more-help
c39c2d00-ba9a-424b-adf9-66af58a0c34b