How to actually run JavaScript in Bridge?

I'm unable to find a straightforward way to add a JavaScript code I previously added. I only see those key / value blocks.

The script was added when configuring the utility extension (Script1), but I'm unable to add it to the Run Script section.

Tags:

Best Answer

  • Brian_Richardson
    Brian_Richardson Overachievers Alumni
    Answer ✓

    There's nothing for it to populate. When you run the Bridge workflow it will run your code and output the results to the Bridge workflow. You can see the results in your Run Log and can reference the results in further workflow steps.

    Be sure that you have a return statement at the end of your code to return the results to Bridge.

    I see that you're writing Javascript to try to access the API though… that's not possible through the Javascript module. Bridge allows Javascript code to run as a step in a workflow, but it's sandboxed. You cannot load any additional libraries, nor can you make API calls out of Bridge.

    As an example of a working Bridge workflow that uses Javascript:

    1. Call API to get report data from Resource Management
    2. Run Javascript: on this step I enter the name of the script ("Get RM data") and the key “rmSourceData” with a value that references the results of the Call API. This passes the report data into my Javascript code, which then uses rmSourceData as a variable. The code also puts together arrays of 500 row objects in Smartsheet format to be used in the next step and outputs those with a return statement.
    3. Child Workflow : with number of runs set as the output of the JavaScript. This is basically a for-each inside Bridge to run the child once for each array that the JavaScript step output.
    4. Child workflow- Add Rows: In the child workflow there’s one step, Add Rows, that takes the array of 500 rows from the JavaScript output and adds those rows to Smartsheet.

    For a more detailed explanation of how this works together you can see my post on it:


    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

Answers

  • Brian_Richardson
    Brian_Richardson Overachievers Alumni

    When you inserted the code in the JavaScript integration, you have to give it a name. Type that name of the script in the Script Name field for the JavaScript step.

    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

  • Brian_Richardson
    Brian_Richardson Overachievers Alumni

    The key/value blocks are there to be able to pass data into your script. For example I use them to pass on the name of a workflow or an array of data for the script to work on

    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

  • lschek1
    lschek1 ✭✭

    The Script 1 is called 'JStest', I just added that name in the Script Name field but nothing happens afterwards, it does not populate a value or a dropdown in those fields in Run Script, so I'm kind of lost.

  • Brian_Richardson
    Brian_Richardson Overachievers Alumni
    Answer ✓

    There's nothing for it to populate. When you run the Bridge workflow it will run your code and output the results to the Bridge workflow. You can see the results in your Run Log and can reference the results in further workflow steps.

    Be sure that you have a return statement at the end of your code to return the results to Bridge.

    I see that you're writing Javascript to try to access the API though… that's not possible through the Javascript module. Bridge allows Javascript code to run as a step in a workflow, but it's sandboxed. You cannot load any additional libraries, nor can you make API calls out of Bridge.

    As an example of a working Bridge workflow that uses Javascript:

    1. Call API to get report data from Resource Management
    2. Run Javascript: on this step I enter the name of the script ("Get RM data") and the key “rmSourceData” with a value that references the results of the Call API. This passes the report data into my Javascript code, which then uses rmSourceData as a variable. The code also puts together arrays of 500 row objects in Smartsheet format to be used in the next step and outputs those with a return statement.
    3. Child Workflow : with number of runs set as the output of the JavaScript. This is basically a for-each inside Bridge to run the child once for each array that the JavaScript step output.
    4. Child workflow- Add Rows: In the child workflow there’s one step, Add Rows, that takes the array of 500 rows from the JavaScript output and adds those rows to Smartsheet.

    For a more detailed explanation of how this works together you can see my post on it:


    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

  • lschek1
    lschek1 ✭✭

    I see, I think I'm getting the gist of it. Just changed the code and tried a simple script with some arithmetic operations and it worked. Thank you so much for the help 😀

  • Brian_Richardson
    Brian_Richardson Overachievers Alumni

    Cool! I wish it was not quite as sandboxed/limited but still with the combination of Bridge and JavaScript you can get very advanced. Post more stuff and watch for Bridge tagged posts…it’s a pretty small community inside the larger SS community so we try to help each other out!

    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

  • lschek1
    lschek1 ✭✭

    Indeed it is, I will definitely be using Bridge more often and post in the forum, thanks for the help.