Forum Academy Marketplace Showcase Pricing Features

Toolbox plugin - collection of utility elements

No -1 return value means “item not found”. You’re not finding your thing.

https://www.w3schools.com/jsref/jsref_indexof_array.asp

Thanks @keith, I could have sworn I read that -1 meant last item, which did seem odd to me at the time, but I must have read/recalled that wrong. Okay, at least I know that it must be something in my search. I’m still wondering though if I can have an expression in the List Item Expression itself, to output the index of the item, without having to use the JS to Bubble element.

1 Like

Would be helpful to see the code in your LIE expression, @louisadekoya

1 Like

I removed the quotes around my var a expression and now it finds something, but it always comes back with 0. I add 1 to the value returned so actually I’m always displaying 1, whether it is the first or second item.

Thanks, @keith. I will put something on a clean page tomorrow and share if I don’t figure it out.

Zero would be first item in list (JS is zero based indices.). Found. (I guess.)

1 Like

@louisadekoya You’re not getting much use of the LIE element, putting a list of texts in and pulling the same list out again.

Try using Expression instead …
['Search for Tasks’s unique id:join with "’,’"'].indexOf('Current Page Task’s unique id')

In the join with, put in ','

Or if you want it set by a workflow action, use the same in a run javascript, with javascript to Bubble as you have.

2 Likes

Thanks @mishav, as it happens I was just reading another of your posts clarifying the join with single quotes around a coma. Pretty sure that is the problem with my current ‘code’. I will give your expression a go. Many thanks.

Thanks @mishav, that works. So simple when you know how.

Nice discovery guys! It works with other things as well as user. I’d better put an example up.

edit page
run page

3 Likes

So useful!

I just figured this was an undocumented feature… are you saying you didn’t know it did that??

(If so… how does it do that automagically?)

Hi @mishav , just wrote an idea post Select app data types in API connector/API workflow so this feature might be implemented in API connector and workflows.

One question : As said before, I noticed this possibility recently, so is it something that was automatically enabled in the JavascripttoBubble element or did you change something in the plugin editor ? If the former, makes me think that it is something that Bubble enable recently…

Passing an existing thing to and from javascript has been possible for a while, discussed earlier in this topic, but it was clumsy.

What is new about @mattmazzega’s discovery is only needing the unique id to reference a thing when returning an “app type” value from a plugin to Bubble.

1 Like

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”

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

8 Likes

Some examples of the server script:

example app editor: https://bubble.io/page?type=page&name=serverscript&id=toolbox-example&tab=tabs-1
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