Applies to

Bridge by Smartsheet

JavaScript module reference

PLANS

  • Bridge by Smartsheet

Run Script

Use this module to write JavaScript functions and fire up the function(s) you wrote.

Image of the Run Script module

Run Script fields

You can use data references in the following fields:

  • Script Name: The name assigned to the required script created from the Integrations page
  • Script Parameters: The parameters the script expects when running, represented as a map of key:value object 
    • Key: The parameter name that appears in the script 
    • Value: The actual value that this parameter needs to take while running the script 

The number of script parameters allowed is unlimited, and they are added dynamically. This means that you can always add more parameters.

What you’ll see in the Run Log pane

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

  • Data
    • result: Desired 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 will appear is “Not found.”
    • Status: The status that the module pulls from Smartsheet
      • These are examples of status labels you might encounter:
        • Succeeded: The module successfully found the information.
        • Failed: The module didn’t find the information.

How-to guides

Use the following examples to practice using the JavaScript Utility. 

Example 1: Hello world

In the Script Body field, type return “Hello” + a.

You must type Return in every script to produce a response. Then add the parameters you defined in the module builder.

Screenshot of the Custom Scripts tab

Make sure 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.

JavaScript module fields

Notice that the Script Name field does not require quotation marks for string inputs, as this is handled by the UI. Whereas in the Script Body field, hello should be specified with quotation marks.

Screenshot of Script Name and Script Body fields

Otherwise, you’ll see the error message presented in the image below.

Error message in the Run Log pane

Example 2: Basic arithmetic

  • In the Script Body field, type return a + b.

A screenshot of the value in the Script Body field

Notice that this method links the two values rather than add them. This is because JavaScript considers the a and b to be object instances, which could have been called in another part of the script body.

Key and Value fields in the JavaScript module

Module result in the Run Log pane

We can define these as number types in the following:

  • return Number(a) + Number(b)

A screenshot of the value in the Script Body field

A screenshot of the result in the Run Log pane

Example 3: Iterate over an array

  • In the Script Body field, type:
function getFields(input, field) {
var output = [];
for (var i=0; i < input.length ; ++i)
    {
        //print only one column
        output.push(input[i][field]);
    }
    return output;
}
return getFields(objArray, field);

The key parameters are the following elements: 

  • field: The key in an object array
  • objArray:The array from which to extract the key 

Product/feature limitations

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

    This is subject to change with the upcoming upgrades.

  • There is no script validation upon script creation. If a script is faulty, it’s the developer’s responsibility to debug/fix any issues and errors returned when running the script.
  • The Smartsheet team doesn’t track or manage script versions and history.
  • 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. So connector-like setups are unreliable and are strongly discouraged.
Was this article helpful?
YesNo