[SOLVED] Why custom state's value refers to itself?

I’ve been working with custom states more recently and there’s something which feels unintuitive to me. This may seem like a silly question and it is not urgent at all, I would just like to get a better feel for the fundamentals.

First, here’s how my website allows users to generate invoices using custom states;

Step 1. The user fills in line-item inputs (description, price, quantity) and the workflow Creates a new LineItem “Data Type” and then stores the data in a custom state _stored_lineitem

Step 2. The user fills in invoice inputs (customer, notes etc) and the workflow Creates a new Invoice “Data Type” called saved_invoice. Along with adding the fields for customer, notes etc, I also add LineItem add list and refer to _stored_lineitem so that the data held in the custom state is added to the Invoice.

My question relates to the custom states Value.


Let’s break down the above custom states Value.

create-invoice’s (this is the page/group which has the custom state)
_stored_lineitem (this is the custom state)
:plus item Result from Step 1 (Create a new line item)

So, the data which the custom state will hold (the value) will be the _stored_lineitem PLUS the Result from Step 1

Why isn’t the value simply Result from Step 1? It appears that the custom state needs to include itself PLUS the Result from Step 1. Can anyone explain why it must include itself?

The custom state needs to “include itself” if it is already storing values and you are trying to add another value to those existing values. In your example, if the custom state is already storing values and you set its value to only the Result of Step 1, you will overwrite everything that is already in the custom state, and its value will only be the result of step 1. If you want to keep the existing values and add the Result of Step 1to those values, you need to refer to the custom state like you are doing (which means you are telling the system to keep the state’s existing values) and then add something to it (in this case, the result of step 1). Make sense?

Hope this helps.



Thanks Mike for the clear explanation, that makes sense now :slightly_smiling_face:

I will update the title of this post to something more descriptive so others can learn/find it in case they were confused about this also.

1 Like

Just want to say this is one of those fundamental pieces of knowledge that are so critical. Thank you @darren.james7518 for asking a very important question and @mikeloc for helping us all.