[SOLVED] Setting custom states for create/edit invoice

Hi guys,

I am finding it hard to make my custom data display correctly.

My users can create invoices and add line-items. When you click ‘Add item’, I store the line item(s) as a custom state.

Here’s how a line-item is saved to the custom state:

The user then sees their line item updated immediately on the invoice page;

The issue

I’ve made the LineItem’s Data source create-invoice's _stored_lineitem which successfully adds line items to the invoice as the user is creating it. But, when a user later returns to view or edit an invoice, the line-item data is missing.

The only way I can get it to show line-item data is to make the LineItem’s Data source Parent group's Invoice's LineItem, but then new line items don’t get added to the invoice as the user is creating it.

Currently I seem to have a choice, either show line-items when creating an invoice OR show line-items when returning to an invoice, but I need both to work! Does anyone have any suggestion on things I could try?

How are you setting the custom state list for existing invoices? (I’m guessing you’re not, which is why the list is empty).

In any case there are two simple solutions…

The first one:
Just use a conditional data source on the RG:

If the Parent group’s Invoice is empty set the datasource as the custom state list.
If it’s not empty set the datasource as the parent group’s invoice’s line items.

The second option:
Just be sure to set the custom state list to the invoice’s line items any time you open the relevant group (i.e. the invoice Group)

Thanks Adam for the quick reply. I did try both these options but neither worked, I possibly did something wrong so here’s how I implemented both solutions.

The LineItem’s Data source iscreate-invoice's _stored_lineitem and I added this Conditional Data source, however line-items still don’t display when returning to the invoice.

Again, the LineItem’s Data source iscreate-invoice's _stored_lineitem and I set the custom state list to the invoice’s line items on the button you click to go to the invoice group, however line-items still didn’t display.

You’re saying when it ‘is empty’. It should be when it’s ‘not empty’

I don’t know why the second option isn’t working but I suspect it’s because you’re using a go to page action, which is probably wiping the custom state (I’m not sure why you need to go to page action on a single page app?)

Ah true, thank you I will change it to when it’s ‘not empty’ and re-test.

I am indeed using a go to page action, I’m impressed how you can know these things without checking, you know so much about Bubble! The reason I am using a ‘go to page’ action is because then the back button will work on my SPA. I noticed several tutorials recommending using ‘go to page’ actions on a SPA but I am sure there are pros and cons.

The following didn’t work, returning to old invoices did populate OK, but there were two problems;

  • new line items don’t populate on the invoice
  • when ‘create new invoice’ the invoice page shows the last viewed invoice

Here’s the code I used:

Ahh… no of course they don’t… (I overlooked that issue) - they obviously won’t if you’re just using the parent group’s invoice’s line items as the datasource, then adding new items…

You could add some additional conditions to address that…

Alternatively, the other option I suggested is probably a better one here - i.e. set the custom state list to be the parent group’s invoice’s line items, then save that list using SET list on the workflow that saves the invoice.

Either that or merge the two lists in the data source (the custom state list AND the parent group’s invoice’s line items) then just ADD the ones from the custom state list when you save the invoice.

As usual there are multiple ways to go about achieving the same end.

  • when ‘create new invoice’ the invoice page shows the last viewed invoice

Then you’re obviously not resetting the data and/or custom state values correctly, So make sure you are in the relevant workflows.

Thanks Adam, I will give this a go. You’re very kind with your time as always, greatly appreciate you.

This one didn’t work, like before the line items do display when returning to an invoice but new line-items are not adding.

I admit this may be over my head, I am unsure what the different between create-invoice's _stored_lineitem and Parent group's Invoice's LineItem because to me they are both calling the same data?

Here’s screen shots of the new settings;


I am not sure how to ADD the ones from the custom state list when I save the invoice. I’m a bit lost here.

I have cleared the data and custom state values so not sure what else I can try. When going to the invoice page I clear the customer custom state:

When adding a new line item I am also resetting inputs.

No… The custom state currently only contains the newly created line_items (which aren’t yet associated to an invoice).

The parent group’s invoice’s line items contains the line_items associated with the invoice.

So they’re not the same at all, and that’s where your problem lies.

You either need to make them the same (i.e. set the custom state to the parent invoices lineitems, as per my second suggestion previously) or merge them into a single list (as per my other suggestion).

Both of which will work just fine if done correctly.

I am not sure how to ADD the ones from the custom state list when I save the invoice. I’m a bit lost here.

If your custom state list is a separate list from the Parent Group’s invoice’s lineitem, just us the ‘Add List’ option in the create invoice workflow action.

I have cleared the data and custom state values so not sure what else I can try. When going to the invoice page I clear the customer custom state:

You need to reset the data of the Invoice Group.

That makes sense, thank you for explaining.

I have done this but it doesn’t work. I am sure I’m probably doing something wrong. I will leave a link to my app in case you have a minute to look.

I did try to adding ‘Reset data’ when going to the invoice page but this didn’t clear the data. When a user clicks on one of their saved invoices on group job-invoices’, they go to ‘create-invoice’ which is populated with their saved data. If they then click back and immediately click the ‘+’ to start a new invoice is is still populated with their saved data. I actually tried an over the top approach and set all states to blank and reset data on every link to and from the invoice page but it didn’t remove any data.

I do find it odd that if I set the LineItem custom state to blank when clicking through to ‘create-invoice’, why then do I still see LineItem’s on the invoice? I have always found the ability to clear data in Bubble a little hit and miss, it does sometimes work but isn’t reliable, have you found this?

Here’s a link to my viewable app, don’t worry if you are very busy, you have already helped so much!

https://bubble.io/page?name=index&id=invoicing-app1309&tab=tabs-6&subtab=General

Maybe you have done this, but in the current version of your app you’re not doing it (maybe you’ve done it before and changed it) - so I can’t really comment on what you’re doing currently…

I did try to adding ‘Reset data’ when going to the invoice page but this didn’t clear the data.

I can’t find where you’re doing that (maybe you’ve removed it?) - but in any case ‘Reset Data’ will do exactly that - it will either rest the data to it’s default value.

I have always found the ability to clear data in Bubble a little hit and miss, it does sometimes work but isn’t reliable, have you found this?

I’ve never experienced that, it’s always worked 100% for me (thankfully, otherwise my apps would have serious problems!!).

Hi Adam, I removed the data reset etc because I didn’t want to leave workflow actions which were doing anything. I can add them back on shortly and try again. Thank you for looking.

Yeah it’s quite an important feature!

If you now go to the workflow and search for ‘When + invoice is clicked’ you can see the following (which still won’t clear the data!)

If you now go to the workflow and search for ‘When + invoice is clicked’ you can see the following (which still won’t clear the data!)

But you’re not resetting anything?.. (only relevant inputs, of which there aren’t any…)

I chose to ‘reset relevant inputs’ just to throw everything at it, I realise that’s a bit silly but I got desperate! Good news, I just solved the issue by using the ‘Reset a group/popup’ which resets the entire group ‘create-invoice’. This seems to work!!!

By the way, whilst you were looking at the app, did you notice anything which may be causing new line items to not show on invoice which are being edited?

There’s no reason why they would show… The RG’s datasource is the parent group’s Invoice’s Line items.

I’ve just changed that to be create-invoice's _stored_lineitem but that doesn’t work either.

The datasource is still the parent group’s invoice’s line items.

It 's not, it’s create-invoice's _stored_lineitem?