51黑料不打烊

Work with JavaScript codes javascript-codes

About JavaScript codes about

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鈥檚 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 51黑料不打烊 Campaign console and Web user interface, the list is identical and operates like a mirror.

Create a JavaScript code create

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鈥檚 properties:

    • Namespace: Specify the namespace relevant to your custom resources. By default, the namespace is 鈥渃us鈥, 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 note
    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 workflow

Load JavaScript code libraries library

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鈥檚 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:

    code language-none
    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 reference

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