Substract a number to list of numbers without negative results

I need some help to do what i want.
For example, I have a data type “points” which contains 2 entries.
This data type has a “quantity” field

The first entry quantity = 30
The second entry quantity = 120

What I want to do is to subtract for example 100 from both entries :
I want to take the 30 from the first entry and the remaining 70 from the second entry.

In the end we get:

quantity of first entry = 0
second entry quantity = 50

Your help will be appreciated


Hi there, @samir.ahres… I would need to create an example to get all of the details right, but a recursive backend workflow is likely the way to go here, and I can see the workflow having at least three steps. The first step would evaluate the entry in question and subtract the entry’s quantity from that same quantity only when the quantity is less than or equal to the total number to subtract. So, using your example, the step would subtract 30 from 30 because 30 is less than 100. The second step would evaluate the entry in question and subtract the total number to subtract from the entry’s quantity only when the result of the first step is empty. So, given your example, this step would not run because the first step was able to run. Finally, the third step would call the backend workflow again only when the result of the first step is not empty, and the process would repeat with the next entry.

One of the details that would need to be worked out (and that I can see being tricky) is how to determine and pass the remaining number to subtract (in this case, 70) to the backend workflow each time it loops. I will leave that one alone for now, but I’m sure it could be figured out.

Anyway, those are some thoughts that come to mind on this one, and I hope it helps.


Thank you @mikeloc
Your idea is not bad, but I can have multiple entries in my data type.

The idea I proposed would support any number of entries in the data type.

yes I misread
the problem is that I am as you say blocked to pass the remaining 70 to the next loop.
i think i can do this with creating temporary data type to save the remaining number

I had actually started to work through an example, and the path I went down was to have a field on the Points data type called previous quantity. Then, the first step of the backend workflow would set the previous quantity field to the item’s current quantity, and now you would have access to that quantity in the last step of the workflow (i.e., the step that runs the backend workflow again).

yes that’s what i did too :wink:

1 Like

did you get it @mikeloc , i’m stuck :roll_eyes:

I think I have an example that would work, but I can’t test it because my sandbox app is on the free plan. Where are you stuck? If you are open to the idea of working through it together in your app, feel free to shoot me a link to your editor (privately), and we’ll see what we can do.

can you show me the screens of your backend workflow ?

Sure… and apologies if it doesn’t work (I don’t like to post suggestions without testing them), but it seems to make sense in my head. :slight_smile:

it only works for the first entry and does not go to the next one

step 2 ok

I would have to be able to see it in your app (with a real example) and mess around with it there in order to try to help any further.

oh no sorry, I made a stupid mistake!
Everything works perfectly
thank you very much for your help
it really helped me

1 Like

Nice! That was a fun one to play around with, so I’m happy to hear it’s working.

1 Like

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