Skip to main content
Known Participant
October 21, 2019
Answered

Conflict between two JavaScripts (I think)

  • October 21, 2019
  • 1 reply
  • 1642 views

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 topic has been closed for replies.
Correct answer Bernd Alheit

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


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 = '';
}

1 reply

Bernd Alheit
Community Expert
Community Expert
October 21, 2019

Use the script as calculation script.

jlehaneAuthor
Known Participant
October 21, 2019

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.