Copy link to clipboard
Copied
I'm using DC Pro and want to create a form that will do calculations. So far I've worked through addition and multiplication. How do I do subtraction. Example: Cost of job is $125. If the job is done 3 times per year the annual cost would be $375. If you pre-pay for the year you get a 10% discount, $375 - $37.50 = $337.50. When I am preparing a form, how do I write the calculation for subtraction?
Copy link to clipboard
Copied
You can do this using the "Custom calculation script" option or the "Simplified field notation" option. Without knowing how your form is set up, it hard to be more specific, but a sample calculation script that subtract one field value from another could be:
// Set this field value
event.value = getField("Text1").value - getField("Text2").value;
The Simplified field notation equivalent would be:
Text1 - Text2
With this option, it's best to not have any spaces or punctuation characters (e.g., ".") in the field names, or else you have to escape them correctly.
Copy link to clipboard
Copied
This is the script I used to make the form work. this.getField("1t4").value = this.getField("1t2").value - this.getField("1t3").value; and it seems to be stable. I didn’t try your example because I didn’t know where the script began or ended. Did it begin at the // Set this field value or did it begin with event.value = getField("Text1").value - getField("Text2").value; or did it begin with getField("Text1").value - getField("Text2").value;
I’m very new to all of this and have very limited abilities for the tasks I’m trying to do. My goal is to create forms my service techs can use in the field on tablets for estimates and contracts that would do the calculations automatically. Calculations would include adding several services over a period of time for totals, subtracting percentage discounts for pre-pays, adding sales tax, total for annual service, then dividing that total by terms of payment (divided by 12 for monthly payment or dividing by 4 for quarterly payments). There are a lot of moving parts with these forms.
The forms I created have been working with the exception of the final calculation. The annual total has been established, but when I divide it by the quarterly payment the math is incorrect. If I open the form with “Prepare Form” right click over the incorrect field value and right click it, go to “Properties”, then go to “Calculate” I can open up the custom calculation script. Here is where it gets weird. If I copy the calculation, delete it, then paste the exact script I just deleted, the field corrects. Now I have the correct calculation. If I don’t do that each time the script will calculate incorrectly each time.
How can I correct this? If it helps I would send you the form. Is it safe to assume that if it gets corrected for one form, I can apply that correction to the other forms?
Thank you.
Copy link to clipboard
Copied
Lines of code that begin with // are comments, so they are not required but help here to provide help.
If the calculation script you posted is in the "1t4" field, the correct script would be:
event.value = this.getField("1t2").value - this.getField("1t3").value;
The problem you describe sounds like an incorrect field calculation order which can fix by:
First go into form editing mode: Tools > Prepare Form
and then in the right-hand panel select: More > Set Field Calculation Order
Find more inspiration, events, and resources on the new Adobe Community
Explore Now