JavaScript module reference

Who can use this?

Plans:

  • Bridge by Smartsheet

Bridge utilities: JavaScript

The JavaScript utility in Bridge includes only one module: Run Script. Use this module to write JavaScript functions and fire up the function(s) you wrote.

Set up the JavaScript utility

  1. Log in to Bridge.
  2. Go to the Integrations page.
  3. Find and select JavaScript.

Run Script module

The module contains the below fields, in which you can use data references:

  • Script Name: The name of the script to run.
  • Script Parameters: The parameters the script expects when running, represented as a map of key: value objects.
    • Key: The parameter name that appears in the script.
    • Value: The value assigned to the key that the script uses while running the script.

The number of script parameters allowed is unlimited, and they are added dynamically.

To set up the script you want to run:
  1. Select the gear icon at the top of the module.
  2. Expand the Scripts section.
  3. Select Add to Scripts.
  4. Fill in the Script Name and Script Body fields.
  5. Select Save.
Brandfolder Image
Javascript modules

Once Bridge runs the Run Script module, the following information will be available in the Run Log pane:

  • Data
    • result: The JavaScript output
  • State: Section that indicates whether or not the module worked
    • Code: The success/error code that the module pulls from Smartsheet.
    • Message: A system-generated message that the module pulls from Smartsheet. For example, if the module can’t find a value, the message that appears is Not found.
    • Status: The status that the module pulls from Smartsheet. The status labels you might encounter are Succeeded and Failed.

Examples

Example 1: Hello world

  1. Create a script in which the Script Body is: return “Hello” + a.

You must type return in every script to have an output.

  1. In the module, add the parameter a with the value world.
  2. Run the workflow.

Ensure that the Key in the module builder matches the parameter in the Script Body field. 

Value is the interchangeable input. For example, it can come from an output from an earlier module response.

The Script Name does not require quotation marks for string inputs, But the Script Body does. Otherwise, you’ll get an error message.

Example 2: Basic operations

To concatenate two strings:
  1. Create a script with the Script Body: return a + b.
  2. In the module, add parameters a and b with values 3 and 2, respectively. 
  3. Run the workflow.
Brandfolder Image
Javascript modules

This method concatenates the two values but does not add them. 

Brandfolder Image
Javascript modules

Variables set through Bridge are treated as strings.

To sum numbers:
  1. Create a script with the Script Body field: return Number(a) + Number(b).
  2. Run the workflow.

With the same parameters from the example below, the result this time is 5.

Brandfolder Image
Javascript modules

Example 3: Iterate over an array

For this example, we have a workflow with the List Sheets module. When the workflow runs, the run log provides the outputs below, where data is marked as Array [100]. This means that the field is an array.

Brandfolder Image
Javascript modules

You need to run the workflow to get the information from the run log.

  1. Select the three dots next to data, then select Copy Data Reference.
Brandfolder Image
Javascript modules
  1. Add a new Run Script module to the workflow.
  2. Create a new JavaScript script. For this example, we name it getFirstElementOfListSheets, and the Script Body is returnlistSheets[0]. This will return the first element of the data array.

The number in the square brackets defines which array element is returned. 0 returns the first, 1 returns the second, and so on.

In the JavaScript module:

  1. Set getFirstElementOfListSheets as the Script Name.
  2. Add a script parameter with Key #1 called listSheets.
  3. Paste the data reference copied in Step 1 into Value #1
Brandfolder Image
Javascript modules

If we run the workflow, the run log provides the outputs below. 

Brandfolder Image
Javascript modules

The items below result are part of the first element in the array.


Product/feature limitations

  • You can only process 6 MB payload requests and responses.
     

    This is subject to change with the upcoming upgrades.

  • There is no script validation upon script creation. If a script is faulty, the developer must debug/fix any issues and errors returned when running the script.
  • Script versions and history are not tracked or managed.
  • Bridge is appropriate for an event or fixed-schedule-based workflows. It isn’t a replacement for the functionality of the one-way or two-way mirror syncing provided by connectors. By design, Bridge makes no guarantees of order nor holds any state about changes made in one system or the other. Connector-like setups are unreliable and are strongly discouraged.