I see what you mean. I have to create the line item first because an invoice can’t be created before a line item has been added (unless there is a way I don’t know of).
Even my line items are not showing up in the data base now? * Ah, the line items are not being saved because I am now saving the new custom state ‘saved-invoice’ which only refers to results of step 1. I need to somehow refer to step 1 and 3! ** I see that is what you meant in your last comment (I am a bit slow tonight)!
Actually it does exist I think because the line item is being created on create-invoice group when the user adds items (done prior to clicking ‘Save invoice’?
Probably the simplest way is to create a new line item every time a user clicks the Add Line Item button, then save that Line Item in a custom state list somewhere.
Then, when you create the invoice just add that list of line items to the invoice, then make changes to that same list of line items and set the newly created Invoice on each line item.
You’ll probably want to set up a backend workflow to delete any line items that get created by never added to an invoice, say after an hour or so (if the User abandons the process).
The other main way to do it is to create the line items on the back end (either running an API workflow on a list, or using a recursive backend workflow).
In any case, the way you’re doing it now will only work if an invoice can only ever have a single line item.
If (as is presumably the case) an invoice can have multiple line items, you’ll need to use one of the methods outlined above (there are other ways too, such as creating loops in the browser using plugins, or looping custom events, but those are probably a bit more complicated).
Yes, I see. Many thanks for your help @adamhholmes - it’s 1am here in the UK so my brain is probably not sharp enough. I will attack this challenge tomorrow!
I thought I would be able to select (Result of step 1) but that’s not working.
Sure you can… just refer to the results of step one as the thing to add to the list…
You’ll need to have a custom state list, of type ‘Line Item’ and add the results of step 1 by setting the custom state value to it’s current value, plus item (result of step 1)
I am not sure if I have solved the issue where an invoice can only ever have a single line item, I think I may have in which case do I need a backend workflow? I will close off for the night and re-read your messages tomorrow - I feel I am a step closer now.
I am not sure if I have solved the issue where an invoice can only ever have a single line item, I think I may have in which case do I need a backend workflow?
Yes, doing it that way you wont need a backend workflow to create the new line items as you’re creating them in the browser…
But, as you’re creating line items every time the ‘New Line Item’ button is clicked, you’ll probably still want to run a backend workflow to ‘clean up’ the database and delete any line items that get created but never finished, say after an hour or so (or maybe 24 hours), just to avoid your database getting cluttered full of unfinished line items for non-existent invoices.
Hi Adam, yes I am just getting started now and the system is working great, again thanks to your help!
One thing, if I create multiple line items, the database displays each on an individual row as well as another row which groups them together. This makes sense because clicking the ‘Save line item’ button first creates a new line item in the database then the final ‘Save invoice’ button takes all the line items from the custom state _stored_lineitem and saves as a consolidated row.
How would you recommend I remove the unnecessary individual rows from the DB?
This works and now the lint items each show in individual rows, whilst the Invoice data type only display one consolidated row. Can you help me understand the logic here though because we are making changes to the LineItem datatype by referring to the Result of step 1, but step 1 doesn’t mention the Line Items as that only creates the invoice! I need to get my head around this!
In short, this is the actions we are taking to create an invoice (with line items);
Create a new line item and save to custom state _stored_lineitem .
Create a new invoice and make changes to Create a new invoice’s Lineitem.
What I don’t understand is how the ‘Create a new invoice’s Lineitem’ works because at this stage the Invoice doesn’t know about line items? I’m not explaining clearly, sorry, but I’m curious how the invoice ‘knows’ it has line items.
You’re adding the line items in step 2 (although I’m not sure why you need two steps - you could do all in that in step 1)
But you’re referring to the Actual invoice (which you created in step 1 and modified in step 2 - but it’s still the same invoice), so it shouldn’t matter which step you refer to (although it might be safer to refer to step 2’s Invoices line items, just to make sure the line items are added to the invoice when you’re trying to make changes to them).
Alternatively, you could refer to the Line Items stored in the custom state (as long as you haven’t cleared the custom state value) - they’re all the same line items.
What I don’t understand is how the ‘Create a new invoice’s Lineitem’ works because at this stage the Invoice doesn’t know about line items? I’m not explaining clearly, sorry, but I’m curious how the invoice ‘knows’ it has line items.
I don’t understand what you mean by that… what is ‘Create a new invoice’s Lineitem’? I can’t see that action anywhere…
but I’m curious how the invoice ‘knows’ it has line items.
Nothing ‘knows’ anything unless you explicitly programme it in… that’s what you’re doing with your workflows (although I don’t really understand what you’re asking about here)
Very true. I have just removed adding the line items in step 2 and instead added that to Step 1. Note that Step 2 is used to convert the invoice number to text because I understood that this must be done in a separate step.
Sorry for my poor terminology. I was just referring to step 3 in the ‘create invoice’ workflow (see below). I make changes to the Lineitems by referring to Step 1 - but step 1 never had any mention of Linitems so I wondered how it could make any changes. I know why I was confused by this, I had forgotten that Step 2 referred to the lineitems so that answers it for me.
Thanks for this tip, I will keep as it is as all is working well I think. I noticed that I am not saving the invoice data on list items, which would make sense because there is no invoice created at the point of creating a line item, I hope this won’t cause issues down the line. I don’t so!
I am so please that the invoice data is showing on html-invoice. Now, the next step is the big one! I can now replace the ‘Save invoice’ button with a ‘Preview’ button. This will take the user to a group call ‘preview-invoice’ and display a PDF of the html-invoice page.
I actually tried this a few months ago and in the end a freelancer said iframe was the only real option. However, I am going to try again. Any tips VERY welcomed!
Also, I’m so grateful for the help you’ve given me, I can’t believe how generous you are with your time and expertise.
This is great advice. I have made note of this and will come back to it once I have the invoice pdf working because then I will have the core functionality of the app sorted.
That’s the whole point of the ‘make changes to a list of lineitems’ action - to set the Invoice on the line items…
but you’re not doing it at the moment (this action is doing nothing in your workflow at the moment)…
You need to set the Invoice field on the line items to be the result of step 1 (the invoice). So click the Change another field button and select Invoice - then set it to the newly created invoice.