Docs Examples FAQ Discussion Thanks

Run Javascript

Expression

Javascript to Bubble

List of Numbers

List Item Expression

Server Script


Examples

Filter a Bubble list
Sort and modify API result
Create list of dates

FAQ


News

Version history

Examples

A sample Bubble app containing Toolbox examples:

Filtering a Bubble list in javascript

  1. A repeating group showing a list of books

    RG properties

  2. Workflow with Run javascript

    workflow step

  3. Run javascript parameter sends the book list to javascript (I could have used a Search instead of the RG)

    parameter with book list

  4. Script to run, filters out any Alex titles, sends the list to Javascript to Bubble

    var mylen = properties.paramlist1.length();
    var mylist = properties.paramlist1.get(0,mylen);
    
    // filter out books with title that starts with Alex
    var myfiltered = mylist.filter(b=>!b.get('title_text').startsWith("Alex"));
    
    bubble_fn_books( myfiltered );
    
  5. Javascript to Bubble returns the filtered list to Bubble

    javascript to bubble properties

  6. Another repeating group shows the filtered list

    RG properties

This example is in the demo app Editor

Sort and modify API result list in javascript

Similar to the previous example, but this time using data sourced from an API call.

Also demonstrates altering an item!

var mylen = properties.paramlist1.length();
var mylist = properties.paramlist1.get(0,mylen);

// show internal name for fields
console.log(mylist[0].listProperties());

// sort descending
mylist.sort((a, b) => b.get('_api_c2_userId') - a.get('_api_c2_userId'));

// alter second item in sorted list
mylist[1] = {
   "_api_c2_userId": 999,
   "_api_c2_id": 888,
   "_api_c2_title": "Bet ya didnt expect this post",
   "_api_c2_body": "Running like rubber chicken"
};

bubble_fn_sorted(mylist)

This example is in the demo app Editor

Using Expression to generate a list of dates

d = new Date().getTime(); 
ds = [];
for(i=0; i<10; i++) ds.push(new Date(d+(i*86400000)));
ds;