Custom state to save temporary inputs in a list

Hi

I’m creating an invoice form where the top part is the Invoice information (customer name, address, date, etc.). The middle part is Invoice items (Description, quantity, value, Total), which is triggered when Add item is clicked. I have two database types, Invoice and Invoice items and they both reference each other.

I would like a way to save the invoice items in a custom state (invoiceItems) until the user is ready to save the full invoice, then transfer the invoiceItems to the Invoice items fields.

I wasn’t able to do this as a list. BTw: my invoiceItems custom state is of Invoice items type and it’s a list.

Why not? What did you try?

You can not make changes to the custom states values without changing the values in the database. Likely you were attempting to reference the custom state which is a list of invoiceItems and attempting to just modify the values of the invoiceItems but via the custom state value and not actually make changes to thing in the database.

Just use the values from the inputs within the repeating group to create the invoiceItems when the user is creating the Invoice.

I tried every possible way. Please send me a step by step if you’re able to.

I feel creating the invoice items before the invoice itself is cumbersome. For one, if the user creates the invoice items in the database and decides to cancel the invoice before creating, we will have to leave these items loose in the database or we need to create a workflow to delete them only if they click a cancel button. On the other hand, a list custom state that temporarily holds all this data can transfer the data only when a Save invoice button is clicked. There has to be a way out.

Manage an Invoice status. You can create an Invoice, default status - Draft. Then user can add all the Invoice Items. When finished move the status to Finalized/ Raised.

I personally do not like to use custom state for such examples because as you said

I was unaware of the details of your setup and only assumed you had already created the invoice items and that was your custom state list value.

In terms of what you are trying to do, which is essentially creating a shopping cart, although it is called an Invoice, it is the same as an Order for a shopping cart with the invoice items basically being order line items. You can not do this with custom states well.

I just put together a shopping cart without touching database using the plugin below.

Please be aware, I have nothing to do with this plugin. I learned about it about 5 months ago and only today had the use case for it and it is great for this type of stuff.

2 Likes

Thank you for recommending our plugin, @boston85719. :pray:

@khalidradwan10
As Matthew pointed out, this plugin allows you to construct your database entities without committing them to the database until it’s necessary. It’s beneficial to have some understanding of JSON, but don’t worry, we’re always here to assist you with the plugin implementation.

Feel free to explore our plug-and-play application, which showcases various examples of the plugin’s use cases (JSONata Element).

This topic was automatically closed after 70 days. New replies are no longer allowed.