Forum Documentation Showcase Pricing Learn more

Toolbox plugin - collection of utility elements


#142

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.)


#143

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”


#144

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.


#145

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.


Variables (custom state) in API workflows
#146

Some examples of the server script:

example app editor: https://bubble.is/page?type=page&name=serverscript&id=toolbox-example&tab=tabs-1
example app: https://toolbox-example.bubbleapps.io/version-test/serverscript?debug_mode=true


Creating, storing, and updating a json file in bubble
API posting an array object
#147

New version 1.1.4

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

#148

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


#149

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!


#150

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.


#151

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


#152

Oh Ok, will take a look.


Javascript toolbox plugin in api workflow
#153

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!


#154

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.


#155

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!


#156

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.


#158

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


#159

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


#160

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: https://bubble.is/reference#ApplicationSettings.language_field

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

navigator.language || navigator.userLanguage


#161

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?


#162

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