Expose MathCalculator result outside RG

I have a RG with a calculated value via a MathCalculator element. I need to expose the calculated value outside the RG so that i can either save it to a field in the Data Type behind the RG or display the sum of these calculated values in a separate group.
I have looked at solving this via custom states but havent been successful yet. I was able to set an Input element’s Initial Content to the calculated value but i cant access the Initial Content value via a workflow.
The MathCalculator element (via the Math Expression Formula Calculator plugin) is needed as i need to utilise BODMAS/PEMDAS rule based calculations which apparently are not supported in bubble. I am not wedded to this approach, so if there are any alternatives please do let me know.

I found a solution using Javascript. I used the Toolbox and Classify plugins to solve my issue and a more general situation wherein one can create sums of calculated fields in a RG or access text element values.

1.After allowing the ID Attributes field to be exposed in the settings, install the Classify and Toolbox plugins.
2. Add a class name for the text box or calculated field (inside the RG) in the ID Attribute field
3. Add a Run Javascript action on the desired event. In the javascript code, you can access the calculated fields via the ClassName you added in step 2. (document.getElementsByClassName("")). Iterate over the elements in this array and increment a variable to add the values of each element via the innerHTML property.
4. You can then either (1) set the value for another IDed bubble element (outside the RG) from the JS script. or. (2) using the JavascriptToBubble element (in the Toolbox plugin) pass a value which can be used to set a custom state.

I dont know Javascript, so this was a bit of a struggle for me. But now i find myself looking at JS for many more situations.
Hope this info helps someone else.

In case your calculations aren’t too complex, you could enable the parenthesis feature via the Settings → Versions tab on your Editor. This will give you a way to set up these calculations natively in Bubble without the need for a plugin.

The JS code might be a little messy to maintain in the long run.

I built the Math Calculator plugin btw, and I’m taking notes from your experience :slight_smile:

Thanks @ranjit , thats a useful pointer. I see that the parentheses feature is still experimental but it will make things much more easy for me.
Your plugin is great. Really helped me in my situation where i needed to do some complex calculations.

1 Like

Parenthesis feature has been stable for quite a few months, so I wouldn’t worry about it.
In fact I wonder why it’s not come out of the experimental features list yet!

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