I'm trying to replicate a simple excel if/then statement into a PDF form. Have tried several things but am just not a Java Scripting guy. Was hoping I could get some help from the community.
I have three boxes that contain cost information. They are labeled LaborCost, MaterialCost & EquipmentCost. Later in the form I have two different output boxes for the sum off my first three boxes. One if it's a positive number and the other if it's a negative number. In Excel forumla language this is what the each of the boxes would read as:
For the 1st result if it's a positive number: @if(+LaborCost+MaterialCost+EquipmentCost>0,+LaborCost+MaterialCost+EquipmentCost,0)
For the 2nd result if it's a negative number: @if(+LaborCost+MaterialCost+EquipmentCost<0,+LaborCost+MaterialCost+EquipmentCost,0)
I'm thinking this should be a simple thing to write out but I'm just not familiar with the proper language sets.
Your colletive help is VERY appreciated.
Try the following as the custom calculate script:
// Sum the field values, as numbers var sum = +getField("LaborCost").value; sum += +getField("MaterialCost").value; sum += +getField("EquipmentCost").value; // Set this field value event.value = sum > 0 ? sum : 0;
For the other one, change the last line to:
event.value = sum < 0 ? sum : 0;
Thank you very much George. I sure appreciate the help I get here. The script you shared with me did exactly what I was loking for.