Toolbox plugin - collection of utility elements

Seems I should write up some documentation for you sometime!

(I always figured complex data types COULD NOT be returned and that those types in the drop down were just “there” as a side effect.)

Whaat? If we collaborated we’d end up with an ebook called Bubble Javascript Integration Guide, it’d get shortened to BJIG, then it’d become a swearword “I’ll bejig this on ya”

4 Likes

Server script broken versions:
v1.1.0
v1.1.1
v1.1.2

Edit - I had to do some funky workarounds for issues from the minification when publishing.

2 Likes

v1.1.3 New Version

  • Server script - to run a Node script on the server, as a workflow step.

This will be handy if you don’t want to create a plugin of your own for server side code.

Uses

  • Calculations and string expressions, regular expressions.

  • Conversions between types, which has been difficult to do on the server side.

  • Set a value to be used by a subsequent workflow step.

I’ll be putting up some examples soon.

Note that you can run the script from a page workflow, the script will be run on the server, so you’ll notice a delay on the app as the client waits for the result.

Limitations
The script will be stopped with an error after a timeout of 10 seconds.

Global variables aren’t reliably available – you can set them up, but there’s no guarantee that the script will run in the same process when you want to retrieve them.

There are a limited number of Node packages/modules available, Bubble has mentioned they will come up with a process for more to be added.

Caution - if you allow untrusted scripts to run, for example submitted by a user, it could break your app’s server scripting environment, and require intervention by the Bubble team.

Node objects and functions you may find useful.

Node modules/objects:
Object
Function
Array
Number
Boolean
String
Symbol
Date
RegExp
Error
EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
JSON
Math
ArrayBuffer
Uint8Array
Int8Array
Uint16Array
Int16Array
Uint32Array
Int32Array
Float32Array
Float64Array
Uint8ClampedArray
DataView
Map
Set
WeakMap
WeakSet
Proxy
Reflect
Infinity
Promise
Intl
Buffer

Potentially useful functions:
parseInt
parseFloat
escape
unescape
decodeURI
decodeURIComponent
encodeURI
encodeURIComponent
clearInterval
clearTimeout
setInterval
setTimeout
get_object_from_id
get_objects_from_ids

Plus the documented functions assigned for a plugin:
context.request
context.currentUser

Remember to refresh the app editor after upgrading a plugin.

9 Likes

Some examples of the server script:

example app editor: toolbox-example | Bubble Editor
example app: https://toolbox-example.bubbleapps.io/version-test/serverscript?debug_mode=true

9 Likes

New version 1.1.4

  • Minor fix to List Item Expression, lookup() was barfing on null value.
1 Like

Hi
I am new to bubble, but I love the javascript plug in you created.

How do I get the javscript to appear in my chrome debugger to step through it?

Thanks

Hi @billalbert05,

You’d need to figure out where in the Bubble app to put a breakpoint, and that isn’t something documented by Bubble or easy to find.

If you have complex javascript, I recommend testing on the console first.

I’m glad you find the plugin useful!

1 Like

Ok, glad I wasn’t missing something obvious. I have debugged it in the console to get it to work, but need to step through to see the data being passed etc.

Any guidance would be appreciated.

You might prefer to create a plugin, the plugin editor can set breakpoints.

Oh Ok, will take a look.

hi @mishav,
I am trying to do a simple calculation using server script on api workflow and use that result for the following steps on the same workflow.

what I am doing wrong? Much appreciated!

Hi @d.norkus
There is no document on the server. To return the value, make sure the last line evaluates to the value.

For example:

var x = 100 - Math.abs(100-(100*a/b));
x;

You could leave the last line out, as the variable assignment in this case evaluates to the same thing, but there are cases where that isn’t true, and I prefer to be explicit about what is being returned.

3 Likes

Hi @mishav thanks for the great work! Question, I’m trying to get the acceptLanguage header of the user which seems to be a server-side function, any chance that your plugin could do it?

Thanks!

Hello, I’m trying to start using this plugin, and tried using the action “Run javascript (client side)”, asynchronous box unchecked, with a simple alert(Current user's Name) which is a text field and it returned me a syntax error.

Using alert("some text") works fine.

How can I use, if possible, dynamic expressions?

I looked into the examples but couldn’t make sense of how to proceed in my case.

Have you tried putting quotes around current user’s name?

2 Likes

Oh, great! That did it. Thought Bubble already fed it as a string.
Thank you!

1 Like

Hi @aissa,

Server-side scripts via plugins are run in a sandboxed area, they don’t have access to the part of the app server that handles browser requests.

It is worth reading this section in Bubble’s reference doc: Introduction - Bubble Docs

Additionally, on the javascript side you can retrieve the browser’s language via:

navigator.language || navigator.userLanguage

1 Like

Hello, i am using your plugin for running javascript when a button is pressed and the plugin returns a list of numbers through a JavascriptToBubble item, lets say: [1,2,3,4,5]

I have a list of items of a certain data type (POSData) and i need to populate one of the fields for this data type with the results returned. However, i have not been able to do this. I was using a workflow api but because these workflows cannot access elements in the index (JavascriptToBubble item) i cannot retrieve this list and had to use a temporary variable to store this list. However, the temporary variable erases all duplicates which i need.

what can i do to fix this?

Why does running the following code in an expression always throw a toolbox error despite always working in my browser console (I’m just trying to get the index of the selected value in a dropdown)?:

document.getElementById("kitchen_open_time").selectedIndex