When I’m building plugins I’ll normally include a function that helps me cover the different possibilities of no value. As follows:
function isEmpty(property){
if (property === '' || property === null || property === undefined) return true;
else return false;
}
You could add this at the start of your script and then say something like:
if (isEmpty(**Search for your item:first item**)) let newValue = 0;
else { **calculate new value**}
One thing that isn’t 100% straightforward is getting a value back out of your script to use later on.
To do this you’ll need to an a Javascript to Bubble element to your page (this will have come with Toolbox). This workaround is needed because Bubble carefully controls how you can get data back into your workflows / database, so it has to come via a plugin.
Set it up as follows - I’ve used a generic name ‘fetchValue’, you could use anything:
Then finally, back in your workflow, you will finish the script with:
bubble_fn_fetchValue(newValue);
where newValue is the name of the variable carrying your adjusted number.
That value will now be available throughout Bubble - either in a Text element / something similar, or in a workflow - by referencing JavascripttoBubbleA’s value