Is this a field with an auto-enter calculation? That would fit what you describe anyway.
I suggest adding a field "NoVAT". Use your button to set it to 1 (this could be the NoVAT field formatted with as a check box.) Then modify your calculation with an If or case function that returns zero or null instead of calculating a VAT from the other fields.
Thank you, getting close to a solution. Now, 2 strange things happen which would be great to correct.
1. For some reason when I press the button to calculate VAT i get an "0" in front of the number. I can manually remove but would be nice not to.
2. The VAT works fine when there is a discount and the VAT calculates from the subtotal field, however if you decide to remove the discount and VAT field still thinks it is there and doesn't revert to the no discount situation.
I'll attach 3 screenshots which demonstrate. I think I need script triggers?
This is my calculation for the green button - INVOICES::Subtotal *.2 & If(IsEmpty (INVOICES::Subtotal) ; ARTWORK::Invoice Total *.2 )
This is the red (clear) button - Clear (Select; INVOICES::Vat)
I would not use scripts to do this calculation. I'd define a calculation
But the main problem that I see is the use of the & operator. This is the concatenation operator that will append the text returned by the expression to the left of & with the text returned to the right of it. This is where you are getting that unnecessary leading zero.
You can rewrite this expression as
If(IsEmpty (INVOICES::Subtotal) ; ARTWORK::Invoice Total *.2 ; INVOICES::Subtotal *.2 )
I think that reproduces the intent of your original expression, but am not sure how that affects whether or not a VAT is calculated and included as part of the transaction total.
Thank you, that is almost there. However, in the situation you add a discount, have the vat calculate off the new subtotal file, but you then decide to remove the discount and the vat is supposed to re-calculate off the top original invoice total field it still thinks there is a discount there.
Attached example (vat should is 20% of Net) but it thinks there is a 10% discount on the artwork still in place.
Do i need a script trigger to refresh the vat field when the - button is pressed? Or something similar?
Which is why I would not do it this way. With a calculation field, modifying the value of a field referenced in the calculation triggers an automatic recalculation and it all happens without any need for a script to calculate the value.
If the button performs a script, that script should be able to recalculate the needed value, but which button are you clicking at this point? If you are clicking a button, you shouldn't need the script trigger as well in most cases.
ok thanks, so I have a calculation field now for VAT and a noVAT field as a checkbox pulling values from a valuelist called NoVat which just has custom values of "1".
In my vat calculation i need to have something like the below (help!) as VAT needs to be calculated from either the invoice total (net) or a new subtotal field if a discount is applied. Screenshot attached.
ARTWORK::Invoice Total *.2 or Subtotal *.2 & If(NoVat)=1 ; NoVat)
have also tried this as a calculated value for my novat field -
If ( NoVat ; 1 ; Vat = 0).
but the VAT field doesn't seem to change.