Copy link to clipboard
Copied
This has been driving me nuts for a few hours and I've just realised what I think the problem is, but I don't know who to rectify it.
In all fields, I have the following custom validation script so I don't get a form full of zeros
if(event.value == 0 | event.value == '') event.value = '';
Problem is, in another field I have the following which says I want a specific field to show zeros, which it's not doing, I'm guessing because of the custom validation script.
if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
}
else {
event.value = this.getField("vat rate.10").value/ 100.0;
}
If I remove the custom validation script, I obviously get a load to zeros appearing. Help please!
This doesn't work, so I know I haven't done it correctly.... 😞
if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
}
} else {
event.value == 0 | event.value == '') event.value = '';
}
You can use this:
if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
if (event.value == 0) event.value = '';
}
Copy link to clipboard
Copied
Use the script as calculation script.
Copy link to clipboard
Copied
Sorry, don't understand.
One is a custom validation and the other is in custom calculation. If I delete the custom validation script, I get zeros appear in all fields even if there is nothing there - see below.
Copy link to clipboard
Copied
If you have a validation script that stops zeros from apprearing, they will not appear. So you need to do this check ONLY when calculating, not when validating. Merge into one script.
Copy link to clipboard
Copied
This doesn't work, so I know I haven't done it correctly.... 😞
if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
}
} else {
event.value == 0 | event.value == '') event.value = '';
}
Copy link to clipboard
Copied
You can't have two else-clauses for a single if-statement. That doesn't make sense.
Copy link to clipboard
Copied
Ok, noted. So how do I merge everything into one script that only puts zeros in the field if Exempt is shown otherwise, the field is blank?
Thanks
Copy link to clipboard
Copied
You can use this:
if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
if (event.value == 0) event.value = '';
}
Copy link to clipboard
Copied
Thank you Bernd - that works great, much appreciated