[SOLVED] Setting custom states for create/edit invoice

I though you were talking about editing an existing invoice, no? (or did I misunderstand that?..)

That’s correct, there is only one create-invoice group which is used for creating a new invoice and editing an existing one. So when returning to a saved invoice, the user may wish to add new items to the existing invoice.

Yes, exactly…

So the datasource for the line items RG is still the parent group’s invoice’s line items (which wont include the new line items, which is why they won’t show).

Ah I see, on the conditional. Right, I’m with you now … changing it now …

Ok, I did that and now saved invoice line-items don’t show. This has been the issue, I can show saved line-items OR create new ones, but never both!

It’s perfectly possible to show both (I’ve already explained two ways earlier in this thread)…

Either merge the two lists into one datasource, then just add the new ones to the database as needed.

Or set the custom state list to match the invoices line items so they are the same (probably the better option)…

There are probably other ways to do it as well, but those are the two simplest ways off the top of my head (and the ones I use for similar use cases in my apps).

I have done this, custom state list does match the invoices line items (screen shots below). I definitely believe you when you say both your solutions are possible, I have tried both but I can’t seem to set them up correctly.

To be clear, new line-items can be added on a new invoice but they are not being added when editing an invoice. I think I may know why, when the line-item is not empty, I am showing the stored (saved) line items create-invoice's Invoice's LineItem. So, when adding a new line-item, that line-item is immediately created so becomes ‘not empty’, thus it defaults back to trying to show the saved line items. I may be wrong but this is where my head is at the moment with it.

I may have to try to merge the two lists into one datasource again (your other solution) but that failed before due to me not understanding how to add the new items to the database as needed, I am at novice/beginner level so get stuck all the time.


I have done this, custom state list does match the invoices line items.

I can’t see anywhere or anyhow in your app that you’re doing that? (maybe I’ve missed it)…

How are you matching the two lists?

I think I may know why, when the line-item is not empty, I am showing the stored (saved) line items create-invoice's Invoice's LineItem . So, when adding a new line-item, that line-item is immediately created so becomes ‘not empty’, thus it defaults back to trying to show the saved line items. I may be wrong but this is where my head is at the moment with it.

That’s not correct - you seem confused about the basic concept here (you’re almost there but not quite).

Let me try to explain…

You have a list of line items that exist on the Invoice datatype (i.e. invoice’s line items).

So when editing an existing Invoice, the line items you want to display are the parent group’s invoice’s line items.

But when creating a new invoice, the invoice doesn’t exist in the database until you save it, so the line items you create here cannot be added to the invoice (it doesn’t exist), so instead are being created, then stored in a custom state list, then added to the invoice once you create it.

That’s all fine - but when editing an existing invoice you’re currently showing the line items for the parent group’s invoice, but you’re not adding the new line items to the invoice - which is why they won’t show.

It really does depend on your exact use-case and desired UX as to what the best way to do what you’re trying to do is, but as far as I can see there are 3 main options…

  1. This is the one I would probably do (it’s probably the simplest and most flexible)…

Just set the data source of the RG to the custom state list. That’s it. Simple.

Then when editing an existing invoice, just set the custom state list to be the Invoice’s line items.

Here you can add or remove line items to the invoice by adding or removing them to the custom state list, then use SET LIST to set that list on the invoice when you save the invoice.

  1. Another way would be to simply use a conditional on the create line item workflow, to add the line item to the invoice if the invoice exists (in fact, you probably don’t even need a conditional - if the parent group’s invoice is empty, the action just wont run)…

or

  1. Set the RG datasource to be a ‘merge’ of the parent group’s invoice’s line items AND the custom state list of line items. It will probably be more complicated if you ned to remove line items from the invoice, but to add them you can just use ADD LIST to add the items from the custom state list (i.e. the new ones) to the invoice.
1 Like

Thank you you helping me understand and for offering the three solutions. I read your reply 3 times and I still believe I have set up solution number 1 so I am unsure why we are seeing different things?

I wonder if you could take a look at my screen shots in my last reply, doesn’t that show the data source of the RG to the custom state list?

Again, I can’t see how this isn’t already the case from my previous screen shots?

Yes it does, but you’ve got a conditional datasource overriding it - so delete the conditionals and you should be good to go.

Again, I can’t see how this isn’t already the case from my previous screen shots?

Nothing in your screenshots shows you doing that (nor anything I’ve seen in your app, although I might have missed it)…

You need to use a workflow action to set the state when opening the Create/Edit Invoice group (i.e. set the custom state list of line items to be the invoice’s line items).

When I delete the conditionals then no line-items display.

Ah, I didn’t realise when you said to set the custom state list that it was in the workflow! I have done this but still not working.

Just so that you know, I am editing the workflow on the cell which users click on to go to view/edit an invoice, see below;

Because the custom state list is empty (hence the need to set it as described above).

The image you’ve posted above makes no sense…

Ok, I think I don’t know how to set a custom state list on the workflow. Sorry, I don’t want to waste your time any more because I feel bad, I am all over the place with it! You’ve been patient and thank you for that.

In the workflow action to set the custom state (in your screenshot) you’re setting the custom state value to itself (which is empty). So the workflow is not really doing anything at all, and the custom state list remains empty.

You need to set the value to the invoice’s line items.

So just set the value to the current cell's invoice's line items.

This was one of the things I tried a few days ago but it doesn’t work. Unless I misunderstood, you mean like this;

Yeah just checked and a couple days ago I had this set up but I think other variables were possibly wrong. I did a spread sheet with about 50 different random variables and I tried them all, I don’t know, just thought I would chance on the right solution!

There’s your problem - you’re setting the custom state list to ‘empty’ when the page is loaded.

I’m not sure what the purpose of that is meant to be?.. so just delete that workflow (or if you really need it for some reason then set up some conditionals to stop it running when you don’t want it to).

1 Like

Damn, yes that’s right, I added that when I was trying to clear the data for new invoices (in hindsight a stupid idea). Wow, how did you find that so fast? I created it myself yet I still didn’t figure that out!

I have deleted it now and the lint items work as you said they would. I really think you should at least have a Patrion or something mate, you just give so much of your time. Thank you so much for sticking with me till this was fixed.

The only issue is that now the ‘create a new’ invoice button no longer clears out the data (it remembers the last viewed). I think I will deal with this another time but this is what I meant earlier about it not being ‘solid’, it works then it doesn’t!

I think I can clear out the data but a strange thing happens, the whole line-item inputs disappear. The ‘add line item’ button is set to hide the input fields so they collapse after each line item is added (for nicer UI). This shouldn’t be causing the issue though because the input fields are set to show by default.

I found it with the debugger (it really is a powerful tool when you know how to use it - almost all of the issues I have with my own apps I solve using a combination of the debugger and the server logs).

The only issue is that now the ‘create a new’ invoice button no longer clears out the data (it remembers the last viewed). I think I will deal with this another time but this is what I meant earlier about it not being ‘solid’, it works then it doesn’t!

Which workflow are you using for this (i cant find it…)

I definitely need to get better with the debugger.