# Sum on invoice items based on invoice

**URL:** <https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731>\
**Category:** Questions\
**Created:** [April 21, 2024, 2:54pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731 "2024-04-21T14:54:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrolli](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jrolli](https://forum.bubble.io/u/jrolli)\
**Post date:** [April 21, 2024, 2:54pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/1 "2024-04-21T14:54:47Z")

</div>

Dear community,

I have an issue summing up data of invoice lines from an invoice data type I created. I tried to have the same logic as the replies on [this question](https://forum.bubble.io/t/sum-of-unique-items-from-the-db/2789/5) but I end up having a blank number.

All my fields are numbers it looks like the “search for” is not working properly.

Any ideas ?

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/8/4/84dbace9b794b406b835eed573a0b06cab327a54.png)

---

<div class="post-metadata">

**Author:** ![hergin](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/hergin/32/199185_2.png) [@hergin](https://forum.bubble.io/u/hergin)\
**Post date:** [April 21, 2024, 2:58pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/2 "2024-04-21T14:58:38Z")

</div>

If the steps before number 7 are calculating the necessary numbers for the step 7, it won’t work. When you schedule an API workflow, it will run asynchronous, so you may not get the response or changes right away.

---

<div class="post-metadata">

**Author:** ![boston85719](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/boston85719/32/77286_2.png) [@boston85719](https://forum.bubble.io/u/boston85719)\
**Post date:** [April 21, 2024, 3:08pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/3 "2024-04-21T15:08:30Z")

</div>

In your backend workflow for creating the invoice items you need to add actions, so that after all invoice items are created you do the totals you currently have as step 7.

---

<div class="post-metadata">

**Author:** ![jrolli](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jrolli](https://forum.bubble.io/u/jrolli)\
**Post date:** [April 21, 2024, 3:29pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/4 "2024-04-21T15:29:51Z")

</div>

Thanks guys.

This seems indeed to be the issue: I created the same logic as in step 7 but in a separate API workflow to run it manually when “invoice items” are created, it works like a charm.

My app’ will create invoices automatically: how to have step 7 run only when the "invoice items " are created ?

EDIT: I am going to look at [this thread](https://forum.bubble.io/t/force-workflow-steps-to-happen-in-order/125022/7) that seems to have the same issue that I have.

---

<div class="post-metadata">

**Author:** ![jrolli](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jrolli](https://forum.bubble.io/u/jrolli)\
**Post date:** [April 23, 2024, 2:51pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/5 "2024-04-23T14:51:21Z")

</div>

For history, here is what I did to resolve my issue.

As my invoices are created by a backend workflow, all the elegant tricks using conditions like adding a boolean return data at the end of the API workflow action and having a condition in the invoice "if API success variable is “yes” (or not empty) in invoice creation workflow did not work.

The only trick that worked was creating a custom event that is call the API workflow to create invoice lines. It’s pretty wild and ugly to look at. If anybody has a better trick: you are more than welcome.

The issue I had then was on the title of the invoice line as " rich text" is not supported in “Custom Events”. Here I used a “seach for” and the method “format as text”. In the “fomat as text” I could do what I want. I added a delimiter “::”. Then I added a split by “::” as a method + “first item”. Same, it’s ugly but works. Same : if anybody finds a better way, I opened to change.

---

<div class="post-metadata">

**Author:** ![boston85719](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/boston85719/32/77286_2.png) [@boston85719](https://forum.bubble.io/u/boston85719)\
**Post date:** [May 4, 2024, 11:46am UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/6 "2024-05-04T11:46:21Z")

</div>

> [@boston85719](#):
>
> In your backend workflow for creating the invoice items you need to add actions, so that after all invoice items are created you do the totals you currently have as step 7.

The above would work. Did you try to implement it? If you did and it didn’t work, share screenshots so I can point out where you went wrong with it.

---

<div class="post-metadata">

**Author:** ![jrolli](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jrolli](https://forum.bubble.io/u/jrolli)\
**Post date:** [May 4, 2024, 12:53pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/7 "2024-05-04T12:53:25Z")

</div>

I don’t think that exactly what I did but the following works:

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/9/c/9cbaaf81aaec9595e0f4e3f5ca39bdb51811c19f.png)

---

<div class="post-metadata">

**Author:** ![boston85719](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/boston85719/32/77286_2.png) [@boston85719](https://forum.bubble.io/u/boston85719)\
**Post date:** [May 4, 2024, 1:22pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/8 "2024-05-04T13:22:19Z")

</div>

The last step is basically the recommendation I made, although there may be ways to improve the previous steps, but at the end of the day, if it works, it works. Glad you got it figured out.

---

<div class="post-metadata">

**Author:** ![jrolli](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jrolli](https://forum.bubble.io/u/jrolli)\
**Post date:** [May 4, 2024, 1:34pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/9 "2024-05-04T13:34:04Z")

</div>

Still, I found it pretty “ugly” as I need to call “customer events” that themselves call “API workflows”…

---

<div class="post-metadata">

**Author:** ![boston85719](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/boston85719/32/77286_2.png) [@boston85719](https://forum.bubble.io/u/boston85719)\
**Post date:** [May 4, 2024, 1:52pm UTC](https://forum.bubble.io/t/sum-on-invoice-items-based-on-invoice/318731/10 "2024-05-04T13:52:53Z")

</div>

I don’t worry about the way things ‘look’, just that they function and do what they need to do.
