[SOLVED] Line-item data not displaying?

You can’t, as you’re using a custom event to create the invoice…

So you’ll need to save the newly created invoice in a custom state somewhere (at the end of the custom event), then refer to that custom state value as the data to send (or set it as an element’s data, and refer to that).

That should work, although there is a chance that the custom state value won’t be set in time to be referred to in the navigate to page workflow action (according to the Bubble docs, when a custom event is triggered the workflow is supposed to pause, let the custom event complete, and then resume - so it should work. But recently I’ve noticed behaviour to suggest that’s not always how it works).

If it doesn’t work, you could always try adding a short pause before the go to page action (although I doubt you’ll need to do that).

Alternatively, you might be able to run the go to page action in the custom event (that depends on why you’re using a custom event), or just get rid of the custom event altogether.

I see, I have created a new custom state called savedInvoice_temp but I can’t see how to refer to step one?

I will then send that data to html-invoice.

No, you need to set the custom state in the custom event, by referring to the step that created it.

1 Like

Ok I appreciate your help, I don’t understand what ‘set the custom state in the custom event’ means but I will take time and come back to this, maybe something will click!

Custom states are weird, but very powerful. If you need it, here are three different explanations of it if it helps. Fully understanding custom states will help you figure out what you need to do when he is saying “Set Custom State at the end of your custom event”.

Bubbles Docs: Using Custom States - Bubble Docs
Zeroquodes: How To Use Custom States in Bubble - YouTube
Buildcamp’s: Custom States | Bubble.io Tutorial - YouTube

To sort of break it down for you (and correct me if I am wrong here @adamhholmes as you clearly are the expert in this string) when you create custom events they do not by default come with the same data handling rules that the built in events do. So when you use Bubble’s “Data → change a thing”, it knows what to do. But a custom state is a blank sheet where you can do anything, but everything you must do.

I may have mixed up the technicalities of it, but that is sort of the “why” of setting your custom state after a custom event.

Best of luck!

Thanks @JakeAtAstonish for the links, I will definitely go through them. I know custom states are very powerful once mastered.

Indeed they are, but also provide a formidable opponent if you haven’t worked with similar things before, not too bad once you make friends with them though!

Haha true! I like to create simple images in mind to understand concepts. So far, I think of a custom state as a type of ‘storage bucket’ in which you can dump data into. The data sits their until you reset the page/groups data. I may be wrong on this analogy but it’s help me a little!

Nice analogy! One thing to keep in mind though is Custom States do not necessarily reset by default. Often you will have to initiate a reset. I do this when I am using popups. I will generally create a popup template as a reusable element and feed a custom state into it. This allows me to only have to create one popup, which then populates with whatever custom state I desire at the time, initiate any functionality, and then clear the state afterwards.

This helps in that now I do not have to create a multitude of different, unique popups, rather only one, which decreases development time as well as it keeps my editor nests much neater.

However, whenever I populate these popups, I will set a custom state, feed my data into the popup, and then I will create a workflow action that clears the custom state. This becomes important because if you are working with, say, an SPA format, that custom state can remain saved (if you do not reset it) and it will be the current state until you reset it. So for my popup example, if I open popup A using a custom state, send data into it, and then forget to reset the state… when I go to open popup B and lets say I have not set a new custom state, then the custom state from popup A will populate popup B, causing a whole rats nest of confusion.

That’s very interesting @JakeAtAstonish and in fact I attempted to do a similar thing with my popups but I found it only worked for groups (on my SPA) which have the same data type. So, if I want one popup to work for ‘delete invoice’ and ‘delete estimate’ and ‘delete customer’, I would have to have three popups because they each have unique data types. Have you figured a way around this? Hold on … this may be very useful for others and is off topic for this thread so I will create a new post for this!

Here it is: Using one popup for multiple tasks

1 Like

Hi @adamhholmes, I set up a custom state called ‘saved-invoice’ to add to the end of the custom event, but I am not sure what the value should be, I tried everything and it’s always red error.

Similarly, when sending data to the html-invoice page, the data to send won’t let me refer to the custom state I just created.

The custom state value should be the invoice you’ve jus created in step 1 (the results of step 1).

Then the data to send will be that invoice (the custom state value).

Oh wow thanks for the fast reply! Ok I will try this now …

That works! The invoice data is now being sent but not the list-items. I guess that is because the results of step 1 is the create invoice step, whilst step 3 is create list items. Should I create another custom state for list items?

You don’t need to send the line items (you can’t anyway, that’s not how it works)…

The line items are associated with the Invoice, so you just need to know the Invoice and you can access the line items.

That’s what I thought initially, so that being the case I wonder why html-invoice is not displaying the line-item data?

Because the data source for your line items RG is the current page’s invoice line items.

but none of your invoices have any line items

So there’s no data to display

Ah that’s true …

LineItem add list is used when creating an invoice so the invoice should have line-item data, I can’t see why it currently doesn’t.

A potential issue is also the fact that line-items are being saved twice, once when a line-item is added to an invoice (this saves it to DB prior to saving the invoice) and then again when the invoice is being created. I did it this way because I am not sure how to save an invoice before line items are added.

Because you’re adding the line item to the invoice in step 1

But you’re not creating the line item until step 3

So it doesn’t even exist when you’re trying to add it…

Although you’re not actually trying to add that - in step one you’re adding a line item that doesn’t yet exist, based on a custom state value which you’re setting somewhere else to be it’s own value (which is empty, because you haven’t even created the line item yet)…

none of that makes any sense at all (it’s all self-referencing its own values, and things that don’t yet exist) - hence why no line items are being added to the invoice.