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.
Best 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:
- Call API to get report data from Resource Management
- 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.
- 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.
- 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:
Answers
-
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.
-
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
-
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.
-
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:
- Call API to get report data from Resource Management
- 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.
- 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.
- 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:
-
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 😀
-
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!
-
Indeed it is, I will definitely be using Bridge more often and post in the forum, thanks for the help.
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.9K Get Help
- 441 Global Discussions
- 140 Industry Talk
- 472 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 496 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives