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

Help with Custom Calculation Script

New Here ,
Feb 15, 2021 Feb 15, 2021

Very new to this so appreciate the assistance!

 

My form  has three subtotal fields

 

COREPOINTS

MGMTPOINTS

C_MPOINTS

 

If the MGMT POINTS field is 0, would like the C_M field to be 0.

 

If the MGMT POINTS field has a value, would like the C_M field to reflect COREPOINTS + MGMTPOINTS.

 

Thank you!

 

 

 

TOPICS
Windows
977
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 , Feb 16, 2021 Feb 16, 2021

As the custom calculation script of "C_M" (or "C_MPOINTS"... Again, you've used both names), enter the following:

 

var v1 = Number(this.getField("MGMTPOINTS").valueAsString);

var v2 = Number(this.getField("COREPOINTS ").valueAsString);

event.value = (v1==0) ? 0 : v1+v2;

Translate
Community Expert ,
Feb 15, 2021 Feb 15, 2021

Is there a space between "MGMT" and "POINTS", or not?

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Apologizes - typo on my part! Thank you..

 

Subtotal Field 1 named COREPOINTS

Subtotal Field 2 named MGMTPOINTS

Subtotal Field 3 named C_MPOINTS

 

If the MGMTPOINTS field is 0, would like the C_M field to be 0.

 

If the MGMTPOINTS field has a value, would like the C_M field to reflect the total of  COREPOINTS + MGMTPOINTS.

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 ,
Feb 16, 2021 Feb 16, 2021

As the custom calculation script of "C_M" (or "C_MPOINTS"... Again, you've used both names), enter the following:

 

var v1 = Number(this.getField("MGMTPOINTS").valueAsString);

var v2 = Number(this.getField("COREPOINTS ").valueAsString);

event.value = (v1==0) ? 0 : v1+v2;

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Thank you!  Sadly it didn't work .. am I doing something wrong?

default8ylk0t09g43s_0-1613488056177.pngexpand image

Screen2.PNGexpand image

 

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 ,
Feb 16, 2021 Feb 16, 2021

Yes, you've not placed it under the correct location. Read my reply more carefully, please.

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Thank you .. it works!!  I am very appreciative!!

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
Enthusiast ,
Feb 16, 2021 Feb 16, 2021

 

Reason I asked you in other post, what do you want  if MGMT field is blank, because  this type of code will show 0 in C_M when MGMT is 0 but it will also show 0 in C_M if MGMT is blank,if it doesn't bother you that way thats ok, but i think it would be better to make C_M blank when MGMT is blank.

Also this will just replicate whatever number is in MGMT field,you should make it to not show calculation until both fields have values.

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 ,
Dec 29, 2021 Dec 29, 2021
LATEST

https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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