Tutorial: Adding and subtracting numbers

What is the answer to life, the universe, and everything? Well, 42 of course. In the comedy science fiction series ‘Hitchhikers guide to the galaxy,’ by Douglas Adams, it took the Deep Thought computer seven and a half million years to reach that conclusion.

The task we have on hand is a bit simpler; and we will take seconds, instead of years. Our question: How do we add two numbers (say, 10 and 2) in a Flow app?

We will use the operator element to do this. We can also do more sophisticated calculations with macros and operators, but that is the topic for another tutorial.

We will use two default numbers to do the math here. In real-life scenarios, we will typically get the values from a service, or from the user.

Let’s get building!

Drag an Operator to the canvas.This opens a configuration panel.

Copy-paste Math in the Name field.

Click New Operation. The operations we can do are dynamically updated based on the values we use (For example, we can do mathematical operations with numbers, empty an object value from a Salesforce list value, and so on.)

Click Select or create a new Value.

Click Create a new Value.

Let’s call the value X. The kind of value should be Number.

Copy-paste 10 in the Default Value field.

Click Save.

Select Add as the option for How do you want to change the Value. As we can guess, if we want to try subtraction, we select the Subtract option.

Select Value Of as the option for How do you want to retrieve the reference Value.

Click Select or create a new Value.

Click Create a new Value.

Let’s call this value Y. The kind of value should be Number.

Copy-paste 2 in the Default Value field.

Click Save to save the value.

Click Apply Operation.

Click Save Operator.This is what the canvas looks like now:

Create an outcome called Go from Start to Math.This is what the canvas looks like now:

Drag a Step element to the canvas. This opens a configuration panel.

Copy-paste Output in the Name field.

Click Insert Value.This opens a dialog box that lists all the values in our tenant.

Search for and select the X value we created earlier.When we run the flow, this will show us the data stored in the X value at runtime.