Skip to main content
Participating Frequently
June 3, 2024
Question

Flexible Substraction

  • June 3, 2024
  • 1 reply
  • 503 views

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;

 

This topic has been closed for replies.

1 reply

PDF Automation Station
Community Expert
Community Expert
June 3, 2024

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}
Participating Frequently
June 4, 2024

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 

PDF Automation Station
Community Expert
Community Expert
June 4, 2024

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