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

Flexible Substraction

New Here ,
Jun 03, 2024 Jun 03, 2024

Copy link to clipboard

Copied

Hello, newbie here. I would like some help on how to achieve subtraction that will not reflect negative on the third field (Execution Score) if the first field (Weight Total) has greater value than the second (Achievement). 
Here are the scripts that I used to do the substraction. Your help is much appreciated. 

1st field 
var v1 = getField("1.7").value;

2nd field
var v2 = getField("2.7").value;

3rd field
v1 = getField("1.7").value;
v2 = getField("2.7").value;
event.value = v1 - v2;

Item37022577xuwf_0-1717455482493.png

 

TOPICS
How to , JavaScript , PDF , PDF forms

Views

140

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 ,
Jun 03, 2024 Jun 03, 2024

Copy link to clipboard

Copied

Assuming you want the value to be zero if it is negative, you can use the following script:

v1 = this.getField("1.7").value;
v2 = this.getField("2.7").value;
var total=v1-v2;
if(total<0)
{event.value=0}
else
{event.value=total}

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
New Here ,
Jun 04, 2024 Jun 04, 2024

Copy link to clipboard

Copied

Hello! I appreciate your response. 

I don't want it to be zero. I just don't want the symbol negative with the number if the 2nd field is greater than the 1st field.
For example: 
 5 - 10 = 5 

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 ,
Jun 04, 2024 Jun 04, 2024

Copy link to clipboard

Copied

LATEST

If you want the actual value of the field to be positive , change event.value=0 to event.value=event.value*-1.  If you want the value to still be negative (because you need the value for other calculations) but you want it to display without the negative symbol you would use only the subtraction equation in the calculation, and add the following custom format script:

 

 

if(event.value<0){event.value=event.value*-1;}

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