[SOLVED] Why is my custom state not working?

I have got into a muddle with something which should be very easy!

My users can create an invoice and choose the VAT rate for the current invoice. I want the 0% to always show as default for new invoices, but it should show the current rate when returning/editing an existing invoice.

Screenshot 2022-09-03 102040

I decided the best way to do this is in two stages, first I set a custom state on the page/group called “vatRate” to store the users choice. Plus, I use the same custom state to set the button colour.

Next, when the “Save” button is clicked I create a new invoice and want to populate the database with the result of the custom state, but I cant refer to the custom state?

Am I approaching this all wrong?

I think the problem is quite minor.
Please check if in your db VAT Rate is a number and state is a text or vice versa.

Second thing about the state is if the page is refreshed or a URL parameter is refreshed the states will be emptied.

Thanks, Ali
Connect with me on Linkedin: https://www.linkedin.com/in/a-imran/
Or book a call to say hi: Calendly - Ali Imran
See me Youtube Tutorials here:

1 Like

It’s obviously a type mismatch, so double check the Type of the field and the custom state…

1 Like

Thank you @adamhholmes and @hafizaliimrankhan you were spot on, I had a mix of Text and number! Now it seems to all work properly but I wonder the best way to clear the custom state so that the 0% button shows as default for a new invoice?

I am thinking that the button which goes to the invoice creation page could set the state of the custom state to 0%. Unless there’s a better way?

Hi @darren.james7518

A custom state doesn’t have any value when the page is loaded/refreshed unless you specify a default value which is probably the easiest way to go, this way you avoid having to pass a variable in your workflow of your create button.

I’m not at my laptop at the mo but I grabbed a screenshot from another forum post just to show you below.

So this would make the custom state 0 by default, then you can change the value when necessary using your button workflows

Thank you for a great suggestion, I do appreciate it but unfortunately the custom state is stored in the browser until it is replaced. I did what you said and set the default to 0, when I create a new invoice it is indeed 0% … however, if I then go to create a second invoice it remembers my previous setting. I need to somehow wipe the custom state clean…

Why can’t you just set it back to 0% in the workflow when you create a new invoice (that would seem the obvious way to me, unless I’m missing something)?

I did just do that, and it does put all new invoices to 0% but when I open any previously saved invoices they all show the same % as the most recent one.

I guess this is two separate issues.

  1. Resetting the vat rate to 0% (fixed by doing what you said)
  2. Ensure a previously saved invoice ‘remembers’. The thing is that the % buttons (0, 5, 20) turn blue based on the custom state, but I really want it to display based on the saved database result … I can’t think how to satisfy both requirements.

vvv

Just set the custom state value to 0 anytime a new invoice is created…

And set it to an Invoice’s saved VAT Rate any time an existing invoice is opened.

I’d use an option set for this personally (if you’re not already)…

I had tried that but can’t figure where I’d do it …

Would I do this on the actual VAT select buttons (image above) or on the link to open a saved invoice?

For example, link to open a saved invoice has this workflow … I don’t see how to set it to an Invoice’s saved VAT Rate?

I have added a condition to the VAT select buttons;

empty

The result of the above is that new AND existing invoices are set to 0%

  • sorry I can see my mistake … one minute!

Just set the value to the parent group’s invoice’s VAT rate.

Ok I am in a muddle … is this correct?

Button ‘Create invoice’ = set the value to the parent group’s invoice’s VAT rate when invoice is empty

Button ‘View existing invoice’ =

ugh … I need to start again and do one thing at a time

No, that’s wrong…

You need to set the value to 0 any time a new invoice is created (regardless of whether the parent group’s invoice is empty or not)…

The VAT select button MUST refer to the custom state or they wont be able to change colour. That is the problem I have …

Ok I will do this first …

Ok I have set the value to 0 any time a new invoice is created…

So now just set it to the Invoice’s save VAT rate when you open an existing invoice to edit.

So now just set it to the Invoice’s save VAT rate when you open an existing invoice to edit.

The blue buttons change depending on which one you click … the way that happens is the custom state. If I remove the custom state and set it to the Invoice’s save VAT rate, the user can no longer change the VAT as the custom state will be gone.

I have tried to add an 'Only when … but it won’t work, I will show you … one min…

Ah, I don’t know how to say “If the user’s saved VAT rate is 20 then make the button turn blue” – basically how can I do that!?

Why are you removing the custom state (sorry, I’m not following what you’re saying here…)

As far as I have tried I can’t have both a custom state AND the Invoice’s save VAT rate. Here is why…

The buttons (0%, 5%, 20%) display as dark blue when the user clicks them. If I show the Invoice’s save VAT rate, I successfully see the users saved VAT rate, but then if they change that to a different rate, the buttons (0%, 5%, 20%) no longer change colour.

If I have both a custom state AND the Invoice’s save VAT rate then two of the buttons (0%, 5%, 20%) go dark blue, the one representing the saved VAT rate and the one triggered by the custom state.