# Using Toolbox plugin & Javascript to trigger a workflow when event = "success"

**URL:** <https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220>\
**Category:** Need help\
**Created:** [June 3, 2021, 9:41pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220 "2021-06-03T21:41:33Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex.pethick](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alex.pethick/32/75019_2.png) [@alex.pethick](https://forum.bubble.io/u/alex.pethick)\
**Post date:** [June 3, 2021, 9:41pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/1 "2021-06-03T21:41:33Z")

</div>

Hi All,

I don’t know javascript, but I’m trying to learn it to solve this problem. I wondered if anyone may be able to point me in the right direction with this question? I’ve been struggling with it for days!!

I’m trying to use the Toolbox plugin to trigger a Bubble workflow when the result of the event is a “success”. How would I approach that with the following code?

[https://jsfiddle.net/rg01vh3z/](https://jsfiddle.net/rg01vh3z/)

I think this part is pertinent but I don’t know to incorpate something like “bubble\_fn\_success(“success”);” into the code in order to trigger the workflow.

`if (result.event === "success")`

Any suggestions? Thanks.

---

<div class="post-metadata">

**Author:** ![robhblake](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/robhblake/32/60625_2.png) [@robhblake](https://forum.bubble.io/u/robhblake)\
**Post date:** [June 3, 2021, 10:25pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/2 "2021-06-03T22:25:35Z")

</div>

Hey Alex,

Not at my PC right now, but from memory:

1. Put the JavaScript to Bubble element on your page and follow the documentation to set it up. Give it a suffix of “close” for example.

2. Enable the “trigger event” checkbox.

3. In the workflows tab add a workflow “when a JavaScript to Bubble event is triggered” → do whatever actions you need like closing a popup etc.

4. Back in your script try:  
if(result.event===“success”){bubble\_fn\_close()};

Then elsewhere in that script define the function:  
function bubble\_fn\_close(){return}

I think that should work - the function gets called and doesn’t do anything however the plugin should register the event and trigger the workflow at point 3 above.

Hope that helps!

Rob.

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 10:48pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/4 "2021-06-03T22:48:20Z")

</div>

I just looked at it, where is your js script?

---

<div class="post-metadata">

**Author:** ![alex.pethick](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alex.pethick/32/75019_2.png) [@alex.pethick](https://forum.bubble.io/u/alex.pethick)\
**Post date:** [June 3, 2021, 10:49pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/5 "2021-06-03T22:49:48Z")

</div>

I added it to an HTML element and it seems to be working (apart from of course what I’m trying to achieve in this thread 🙂

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 10:50pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/6 "2021-06-03T22:50:03Z")

</div>

I made the changes

```
bubble_fn_close(true)
```

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 10:52pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/7 "2021-06-03T22:52:40Z")

</div>

I just saw the jsFiddle, let me make the changes  
`if (result.event === "success") { myUploadWidget.close(); }`

This is where you want your `bubble_fn_close(true)` correct?

---

<div class="post-metadata">

**Author:** ![alex.pethick](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alex.pethick/32/75019_2.png) [@alex.pethick](https://forum.bubble.io/u/alex.pethick)\
**Post date:** [June 3, 2021, 10:55pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/8 "2021-06-03T22:55:34Z")

</div>

I believe so. Honestly, I’m just delving into all of this and I have very little knowledge of javascript. I just had to use it in this instance.

I really appreciate both of your help! It works!

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 10:55pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/9 "2021-06-03T22:55:37Z")

</div>

You can test it out now, should work as expected.

---

<div class="post-metadata">

**Author:** ![alex.pethick](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alex.pethick/32/75019_2.png) [@alex.pethick](https://forum.bubble.io/u/alex.pethick)\
**Post date:** [June 3, 2021, 11:04pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/11 "2021-06-03T23:04:36Z")

</div>

Thank you VERY much.

Related question:

This page serves as a way for users to be able to upload video. After that’s successful, they’ll be taken to another page, which is why I was trying to get this working to trigger that event.

However, because users upload the file directly through the browser and it’s uploaded to Cloudinary for storage (as opposed to into Bubble database/AWS and then to Cloudinary) I’m running into this problem where I’m trying to figure out how to store some kind of unique identifier for the file and create a database entry for that user so that when the file is uploaded, I know which file to retrieve from Cloudinary on the next page (or in the future). Otherwise the upload modal disappears and I have no idea what the video file is!

Any thoughts on how to approach that? Does that makes sense? Either way, I appreciate your help from before.

Like I said, I’m not a developer, so I’m trying to figure this all out of the fly. I think it may be the public\_id, but I don’t exactly know how to go about this in Bubble + with javascript: [Upload API Reference | Cloudinary](https://cloudinary.com/documentation/image_upload_api_reference#upload_optional_parameters)

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 11:05pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/12 "2021-06-03T23:05:35Z")

</div>

That depends if Cloudinary returns anything after the image has been uploaded. Let me check it out.

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 11:06pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/13 "2021-06-03T23:06:53Z")

</div>

So it returns all of this:

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/9/b/9b834f8f5ec87fbc041f93dd8d6c12861059899b.png)

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 11:07pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/14 "2021-06-03T23:07:44Z")

</div>

You can return any of these values to Bubble using the same JStoBubble element you have. You just have to change the “yes/no” to “text”

---

<div class="post-metadata">

**Author:** ![alex.pethick](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alex.pethick/32/75019_2.png) [@alex.pethick](https://forum.bubble.io/u/alex.pethick)\
**Post date:** [June 3, 2021, 11:11pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/15 "2021-06-03T23:11:41Z")

</div>

OK awesome, I didn’t know you could see that in the console. But how do I specifically structure that in the script to focus on say the “public\_id” parameter?

Sorry to have to ask so many questions.

---

<div class="post-metadata">

**Author:** ![shawnmi6](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/shawnmi6/32/96625_2.png) [@shawnmi6](https://forum.bubble.io/u/shawnmi6)\
**Post date:** [June 3, 2021, 11:12pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/16 "2021-06-03T23:12:12Z")

</div>

Can you jump on a call right now? faster to explain over the call

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [August 12, 2021, 9:41pm UTC](https://forum.bubble.io/t/using-toolbox-plugin-javascript-to-trigger-a-workflow-when-event-success/154220/17 "2021-08-12T21:41:41Z")

</div>

Closed on August 12, 2021, 9:41pm UTC

This topic was automatically closed after 70 days. New replies are no longer allowed.
