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

Conflict between two JavaScripts (I think)

Contributor ,
Oct 21, 2019 Oct 21, 2019

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!

TOPICS
Acrobat SDK and JavaScript

Views

1.1K

Translate

Translate

Report

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

Votes

Translate

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

Votes

Translate

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

Copy link to clipboard

Copied

Use the script as calculation script.

Votes

Translate

Translate

Report

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

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.

clipboard_image_0.png

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thank you Bernd - that works great, much appreciated

Votes

Translate

Translate

Report

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