Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Conflict between two JavaScripts (I think)

Contributor ,
Oct 21, 2019 Oct 21, 2019

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!

TOPICS
Acrobat SDK and JavaScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Contributor , Oct 21, 2019 Oct 21, 2019

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

Translate
Community Expert , Oct 21, 2019 Oct 21, 2019

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 = '';
}
Translate
Community Expert ,
Oct 21, 2019 Oct 21, 2019

Use the script as calculation script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 21, 2019 Oct 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.

clipboard_image_0.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 21, 2019 Oct 21, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 21, 2019 Oct 21, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2019 Oct 21, 2019

You can't have two else-clauses for a single if-statement. That doesn't make sense.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 21, 2019 Oct 21, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2019 Oct 21, 2019

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 = '';
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 22, 2019 Oct 22, 2019
LATEST

Thank you Bernd - that works great, much appreciated

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines