Toolbox plugin - collection of utility elements

Only worried about string values so that worked perfectly. Thank you so much for you help.
Have just sent over something as a thank you!

1 Like

Thanks for nice plug-in, and I have little issue.
I created a script to sort images according to their labels.

This works fine. However, the data is not saved.

Both toolbox elements and states are updated with correctly sorted lists.

However, no matter what method you use, the data cannot be changed.

However, if I press the button twice, the data changes the second time. Could you tell me why?


image
image

Great that it works! If you find out why “x” matches everything, you’ll want to exclude the field named _id

Awesome, thank you!

Basically the workflow is seeing JS2B’s value as at the start of the workflow.

Did you try turn off “Asynchronous” in RunJS?

If it still has the problem, look at FAQ on JS2Bubble for an explanation and some workarounds.

Thanks for rapid answer. I already turn off it.
Can you check mine? look at asd page
if you do twice, it will change data.
so after that you should delete sorted image list data for next text

@studio.be.lazy The Bubble optimizer will see that at the start of the workflow there is enough data to run the database step on the backend, without waiting for the prior steps.

The saving part needs to be on another workflow, as described in the FAQ.

1 Like

I did it! Thanks for explaination!

1 Like

Im getting the following error when i search for a property on my site. The error only occurs on mobile. The website is MorningAgent.com.

Here is the error:

The plugin Toolbox / action Run javascript threw the following error: eval code@
eval@[native code]
anonymous@ (please report this to the plugin author)

Here is the Javascript:

What mobile OS and browser?
On an android mobile, Chrome says bubble_fn_result not defined, Firefox gives a more generic message.

Usually this means the JStoBubble element is on part of the page that is hidden, so is not being rendered, so the function doesn’t get created. Maybe hidden because of the responsive layout?

Also, for the RunJS script I recommend using a parameter for user input, so it won’t break on characters such as double-quote.

EDIT - the JS error doesn’t occur on my mobile in landscape orientation.

how to run node modules in server script action in the backend .

Not mentioned in the documents, but it might be useful for someone. When a list of text is sent to the server script, properties.thinglist1 becomes an object instead of a function. You can access its elements using properties.thinglist1[“_pointer”] instead of .get(0, 
)

Help me please @mishav
I’m running this code:

const log = [];

function listToArray(list) {
  if (!list) {
    return [];
  }
  if (Array.isArray(list)) {
    return list;
  }
  try {
    return list.get(0, list.length()); 
  } catch {
    return [];
  }
}

function checkListLength(list) {
  try {
    return list.length();
  } catch {
    return 0;
  }
}

function intersect(a, b) {
  var setA = new Set(a);
  var setB = new Set(b);
  var intersection = new Set([...setA].filter(x => setB.has(x)));
  return Array.from(intersection);
}

function contain(a, b) {
   return intersect(a, b).length === b.length;
}

function getField(data, name) {
  return data._pointer._source[name];
}

(function () {


const affiliates = listToArray(properties.thinglist1);

if (!properties.thing1) {
  return affiliates.map(aff => aff.get("_id"));
}

const rules = listToArray(properties.thinglist2);
const answers = JSON.parse(properties.thing3);

const affiliateToRulesMap = {};
for (let rule of rules) {
  const affiliateId = getField(rule, "affiliate_user");
  affiliateToRulesMap[affiliateId] = affiliateToRulesMap[affiliateId] || [];
  const choices = getField(rule, "choices_list_text");
  const formFieldId = getField(rule, "formfield_custom_formfields");
 
  affiliateToRulesMap[affiliateId].push({
     choices,
     formFieldId
  });
}

const affByCondition = affiliates.filter(aff => {
  const affId = aff.get("_id");
  const rules = affiliateToRulesMap[affId];
  if (!rules) {
    return false;
  }

  return rules.every(rule => {
     const choices = rule.choices;
     let fieldAnswer = answers[rule.formFieldId] || [];
     if (typeof fieldAnswer === "string") {
        fieldAnswer = [fieldAnswer]
     }  
     return contain(choices, fieldAnswer);
  });
}).map(aff => {
  return aff.get("_id");
});

return affByCondition;
})()

And on the version 1.3.1 of the plugin it worked, but with newest version 2.1.2 it’s not.


I understand it’s not typically safe to access sensitive info like API keys on Bubble’s front end workflows, but does this toolbox offer an exception? If an API key is stored in my database, can I put auth variables in the javascript, set the API key as one of the variables, and then grab the variable when the code runs? In my head, this would work similar to have a .env file with API keys, but not sure and would love some help.

Hello,
Can we use 2 times the toolbox plugin (2 windows as on my picture) in the same workflow and set 2 different conditions so that when one of the 2 conditions is met it is one or the other of the plugins (one of the 2 windows) that is activated with its code, of course the code is different in the 2 windows.

Thank you very much for your help, I really need it.

@dev77 how did you go on converting your serverscript? Did you find the relevant page on Toolbox docs?

Tip: you’ll likely want to make async functions wherever they wait on promises, for example

becomes

async function listToArray(list) {
  ...
  try {
    return await list.get(0, await list.length()); 
  } catch {
    return [];
  }
}

Then this

becomes this

return (async function () {

const affiliates = await listToArray(properties.thinglist1);
...

You can do this, but the script and parameters are visible in the server log. So it depends on the particular use case, for example if the key is considered okay to be visible by anyone with access to server logs, including Bubble support staff.

Another thing to check is if the key shows on the on-page workflow debugger.

Yes that is a useful way to run conditional scripts.

You can also rename the workflow step to make it clearer about which code is in which step.

Thank you for your message.
I’d also like to know what the JS part of the front end is for?
In my case I would like a group to zoom in, when a certain condition is met it will zoom out to the left and when a different condition is met it should zoom in to the center.

can you tell me more about the font part of the plugin please?

The element is intended to receive a call from Javascript, to raise a Bubble workflow event and set a Bubble value. If you upgrade the Toolbox plugin, it will show the url of a doc site, which explains more and links to a bunch of examples.

Can you say more about the condition? Can it to trigger an event? Or need it be checked on a polling loop?

Have you got a zoom technique you want to use?

If you are talking about JStoBubble’s style properties, they do nothing significant. The element is not intended to display anything.

Yes, the condition is to check a query loop.
And when I talk about zooming, I mean enlarging a group towards the center.