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

Form field calculation

Community Expert ,
Jun 20, 2017 Jun 20, 2017

First of all, It is not clear to me whether I'm posting this question in the right forum.

I created an interactive fillable form, some fields should be filled by hand, calculations was done in Acrobat Pro to automatically displayed formula results.

Screen Shot 2017-06-20 at 1.37.05 PM.png

Here is what is expected to happen in the red framed fields:

  1. QTY.: User will type-in the quantity being requested
  2. Requested date: User will type-in the request date (see #4 below)
  3. Unit Price: User to type-in Unit price
  4. Total Price: is an auto calculation. If "Request date" is 1st of June, then formula is as follows [ Qty x Unit Price ]. If the date is not 1st of June then formula should be as follows [ Qty x Unit Price / 2 ]

How can I make the Total Price to use If/Then formula, must this be scripted?

TOPICS
Acrobat SDK and JavaScript
1.8K
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 1 Correct answer

Community Expert , Jun 20, 2017 Jun 20, 2017

Try this code:

var v = Number(this.getField("QTY. Adobe CC complete").value) * Number(this.getField("Unit Price Adobe CC complete").value);

if (this.getField("Request date").valueAsString!="01/06/2017") v = v/2;

event.value = v;

Translate
Community Expert ,
Jun 20, 2017 Jun 20, 2017

Yes, this is the right place, and yes, this can be done using a script.

What format is the date field using?

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 ,
Jun 20, 2017 Jun 20, 2017

Qty and Unit Price fields are numbers only, while the Request date is dd/mm/yyyy

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 ,
Jun 20, 2017 Jun 20, 2017

You can use the code given above, then, just add ".valueAsString" after this part: this.getField(" ??Request date?? ")

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 ,
Jun 20, 2017 Jun 20, 2017

"value" gives the same 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 ,
Jun 20, 2017 Jun 20, 2017

But you didn't include either one in your code, so it's not going to work as-is...

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 ,
Jun 20, 2017 Jun 20, 2017

OK, I forget it.

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 ,
Jun 20, 2017 Jun 20, 2017

Thank you both @Bernd Alheit and try67​ for jumping in with the script. Unfortunately I'm getting this error after adding ".valueAsString"

The error reads: SyntaxError: missing ) after condition.

Below is the script I entered.

event.value = this.getField(" ??QTY. Adobe CC complete?? ").value * this.getField(" ??Unit Price Adobe CC complete?? ").value;

if (this.getField(" ??Request date?? ")  ".valueAsString" != "01/06/2017") event.value = event.value / 2;

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 ,
Jun 20, 2017 Jun 20, 2017

Try this code:

var v = Number(this.getField("QTY. Adobe CC complete").value) * Number(this.getField("Unit Price Adobe CC complete").value);

if (this.getField("Request date").valueAsString!="01/06/2017") v = v/2;

event.value = v;

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 ,
Jun 20, 2017 Jun 20, 2017

Perfect. It worked.

Much appreciate your assistance.

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 ,
Jun 20, 2017 Jun 20, 2017

You must use the correct field names in the different rows.

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 ,
Jun 20, 2017 Jun 20, 2017
LATEST

Just did with another row with different field name, it woks there too after changing corresponding name within the 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
Community Expert ,
Jun 20, 2017 Jun 20, 2017

You must use JavaScript for this:

event.value = this.getField(" ??Qty?? ").value * this.getField(" ??Unit Price?? ").value;

if (this.getField(" ??Request date?? ") != "01/06/2017") event.value = event.value / 2;

In the code you must use the correct field names.

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