Creating Invoice from Work order view

Creating Invoice from Work order view

I am creating invoicing, work order and work log functionality into my app.

I created work orders and work logs via the sub-form work-around as per the help guide (a 'log work' button in the work order view'). I now want to add invoicing, but that won't work the same way, as the relationship goes the other way. I want to be able to select the work orders to invoice from the work order view and then use a custom action at the bottom that invoices the lot of them.

I would like to have that be the only way to create an invoice to keep things streamlined. You don't have to first create an invoice, then add work orders to it, you can do it all at once, as you select the work orders.

My original plan was to have the custom action create the invoice (easy) with the add record function. Cake. Trouble is, then I want to set a 'invoiceNumber' field in the work order to that newly created invoice's number. How can I reference that newly created invoice's number? Is there a way to make it return that value?

I think that  I 'could' add the work order ID to the invoice instead, into a multi-line or something, but that just sounds ugly. Much better to have the invoice number stored in the work order, no?