# Complex Calculation with Custom Code

**URL:** <https://forum.bubble.io/t/complex-calculation-with-custom-code/32000>\
**Category:** Need help\
**Created:** [June 24, 2018, 12:45am UTC](https://forum.bubble.io/t/complex-calculation-with-custom-code/32000 "2018-06-24T00:45:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![akerezy](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@akerezy](https://forum.bubble.io/u/akerezy)\
**Post date:** [June 24, 2018, 12:45am UTC](https://forum.bubble.io/t/complex-calculation-with-custom-code/32000/1 "2018-06-24T00:45:52Z")

</div>

Hi,  
I have a complex financial calculation dealing with financial payments… is there a way to:

a) create a custom function that takes input from a form and does the calculation  
b) takes the output of that function and sets it to an input value?

Thanks  
Alex

---

<div class="post-metadata">

**Author:** ![sridharan.s](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sridharan.s/32/17881_2.png) [@sridharan.s](https://forum.bubble.io/u/sridharan.s)\
**Post date:** [June 24, 2018, 2:07am UTC](https://forum.bubble.io/t/complex-calculation-with-custom-code/32000/2 "2018-06-24T02:07:58Z")

</div>

Yes. You can pass the data through an API to wherever you’re hosting your custom algorithm and then you can pass it back to Bubble via the API as well.

We’ve used amazon Lambda to host our algorithms. It’s quick and easy to set-up, highly performant, and it happens to be super cheap too.

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [June 24, 2018, 2:45am UTC](https://forum.bubble.io/t/complex-calculation-with-custom-code/32000/3 "2018-06-24T02:45:38Z")

</div>

To add to Scott’s excellent post …

A general rule to help decide whether to put the calculation in javascript on the page vs through an API.

Javascript:  
When all the data for the calculation is derived from the page or is from available to the user from your app.

API:  
When you don’t want to share the calculation method with the user.  
When the calculation uses additional data from your app that you don’t want to share with the user.  
When the calculation uses other APIs, and your app isn’t retrieving them.  
When the calculation needs to be initiated by the server (API workflow).

---

<div class="post-metadata">

**Author:** ![akerezy](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@akerezy](https://forum.bubble.io/u/akerezy)\
**Post date:** [June 24, 2018, 3:03am UTC](https://forum.bubble.io/t/complex-calculation-with-custom-code/32000/4 "2018-06-24T03:03:38Z")

</div>

Thank you so much… is there a tutorial on how to put custom javascript on a page???

So far the software has a steep learning curve for me, but javascript is easy… getting it on the page will be the challeng

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [June 24, 2018, 3:18am UTC](https://forum.bubble.io/t/complex-calculation-with-custom-code/32000/5 "2018-06-24T03:18:59Z")

</div>

@akerezy connecting javascript with Bubble is not easy, but has been done.

## Including javascript

- Settings \> SEO/Metatags \> Script in header/body
- Page HTML Header
- HTML element
- Some plugins like Toolbox (self promotion hehe)

## Executing javascript / passing values to javascript

- Making a HTML element visible
- Plugin actions, like Toolbox “Run javascript” or “Expression”

## Passing data from javascript to the Bubble page:

- Funky workarounds using an edit control’s value
- Some plugins elements, like Toolbox “Javascript to Bubble” or “Expression”
- You can also write your own plugin to do custom integration.

Toolbox plugin has a (long) discussion topic, and links to some example apps.

> [@Toolbox plugin - collection of utility elements](http://forum.bubble.io/t/toolbox-plugin-collection-of-utility-elements/11264):
>
> Announcing Toolbox, a plugin containing some element-based utilities. [image] [image] #List of Numbers Generate a list of numbers. Can be used to create a data source for a repeating group or dropdown. [image] #Javascript to Bubble Call a function from your custom javascript, to trigger a Bubble workflow event, and pass a value to be made available in Bubble. Properties: [image] Published value: [image] Sample HTML element: [image] Result: [image] #Expression Enter an expres…

There are other plugins that do similar things to Toolbox.

---

<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:** [September 2, 2018, 12:45am UTC](https://forum.bubble.io/t/complex-calculation-with-custom-code/32000/6 "2018-09-02T00:45:52Z")

</div>

Closed on September 2, 2018, 12:45am UTC

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