Exiting bubble workflow

I’m trying to build my own plugin. I need to either exit the whole subroutine so that no other code in the workflow executes or somehow expose a boolean variable in my code into the workflow so that i can utilize the ‘Only When’

var canPrint;

if (confirm(“When you press print, the system will recategorize the current items on the page as ‘done’ and will not be able to be printed again, unless saved as a pdf.”) == true) {

    canPrint = true;
    window.print();

} else {

canPrint = false;

}

if (canPrint = false) {
return;
}

Using return should cover you the first need - exiting your routine.
And you can create and use and Exposed State for your second need.

Let’s say that you want your canPrint variable to actually be an Exposed State accessible from workflows.
Firstly, create an Exposed State within the Plugin Editor - it’s just the same as creating a field - but in the next section of the editor… so you will assign a type etc. You could use True / False for yours.

Then you can assign values to it within your code using instance.publishState(state name, state value);

So yours would look like:

instance.publishState("canPrint", "yes");

Thank you for the quick response!

i said executes but what i meant was “Exits”. i want to exit the entire workflow if my plugin was cancel

Feel free to direct message me the code from your Initialise and Update functions within the Plugin Editor, along with a description of what you are trying to achieve and I will take a look. Right now I’m not too sure what you’re setting out to do.

sorry for the confusion.

I have a print button, and once the print button is executed it will display the window.print method based on whether or not the message box was OK or Cancel. If it is cancelled, i want to exit the rest of the workflow on the button in the workflow editor. It seems that my return only allows me to exit a function within my plugin; which will still execute the rest of the workflow.

Hey Doug - to build this in the Plugin Editor you would need to define an Event, and then build a Function within your plugin code that is triggered when that Event is called through a workflow. Upon display of the message box, and the capturing of the user’s answer you will need to pass an Exposed State back to the workflow.

If you are not too sure how to do that then I think you have three options - personally, I would go Option 1!

  1. Stay clear of the plugin editor. It feels like you are using a sledgehammer to crack a nut. The best thing about Bubble is that you can build out what you want to achieve without using code. Instead of displaying a message box, why not display a Floating Group that contains your “Ok” and “Cancel” buttons. You can really easily then change a Custom State based on the button clicked by your user, and that State can trigger the outcome that you want for each option. Not only is this easier, it will likely be a better user experience for your app visitors.
  2. If you really want to code this then take a look at the Toolbox plugin. You can incorporate JavaScript actions directly into your workflows, although I’m not 100% sure if you can edit Custom States through it.
  3. Hire someone to build your plugin. It’s not a huge job but could eat up a lot of your attention if you’re new to it, relative to the size of the task you want your plugin to do.

Thinking outside the box. WOW option 1 is such a great idea. why didn’t i think of that? You’re a life-saver!
I don’t know how you feel about people telling you they love you but, i love you.

1 Like