How to Format a Number for Use in a Later Step After Subtraction?

This topic was automatically generated from Slack. You can find the original thread here.

How do I format a number so I can use it in a later step? Like I want to take a number, subtract a number from it, then use the result in a later step.
Thanks all.

Hi Nizar, let’s see how does on this

Hi! It looks like you want to format a number, subtract another number from it, and use the result in a later step. Here’s an example Pipedream component that demonstrates this: export default defineComponent({ props: { number1: { type: "integer", label: "First Number", }, number2: { type: "integer", label: "Second Number", }, }, async run({ steps, $ }) { const result = this.number1 - this.number2; return result; }, }); In this example, you can input two numbers using the number1 and number2 props. The component will subtract number2 from number1 and return the result. You can then use this result in a later step of your workflow.

Ah cool. So I can just use this whole snippet as a step?

that’s right, just add a new Node.js code step and paste that code in, editing where necessary

Need some help. I added this code, but where exactly do I put in my numbers. I am not sure what to replace in here.
My 1st number will be from a previous step and 2nd number, I need to put in manually.
Thanks!

can you help?

Of course! To use a number from a previous step and subtract a manually entered number, you can modify the component code like this: export default defineComponent({ props: { previousStepResult: { type: "integer", label: "Result from previous step", }, numberToSubtract: { type: "integer", label: "Number to subtract", }, }, async run({ steps, $ }) { const result = this.previousStepResult - this.numberToSubtract; return result; }, }); In this code, you can input the result from the previous step using the previousStepResult prop and input the number you want to subtract manually using the numberToSubtract prop. The component will subtract numberToSubtract from previousStepResult and return the result. You can then use this result in a later step of your workflow. To use this component, add a new Node.js code step in your workflow, paste the code above, and replace the values for previousStepResult and numberToSubtract as needed.

ah, so all the instances where it says PreviousStepResult and NumberToSubtract, I’ll use the values I want. yes?
Got it. (hopefully)

yes, when you add this code and click the Refresh Fields button at the top of the code step, you should see inputs appear above the step. That’s where you can add any static numbers or reference data from previous steps

ah, I see it now, super! :slightly_smiling_face: