Skip to main content
bryansidlsi
Participant
March 14, 2019
Question

How do I set a minimum value of $20 to show up in a field called (Primer Total) if Field (P1) X (P1-Cost) is lower than $20

  • March 14, 2019
  • 1 reply
  • 298 views

How do I set a minimum value of $20 to show up in a field called (Primer Total) if Field (P1) X (P1-Cost) is lower than $20

This topic has been closed for replies.

1 reply

TᴀW
Legend
March 14, 2019

Try something like this, as a custom calculation script:

var allFields = ["P1","P1-Cost"];

var i, theProduct = null, theValue;

for (i = 0; i < allFields.length; i++){

   theValue = Number(this.getField(allFields).valueAsString);

   if (isNaN(theValue)) continue;

   if (theProduct === null) theProduct = theValue;

   else theProduct *= theValue;

}

if (theProduct < 20) theProduct = 20;

event.value = theProduct;

In the allFields array (first line) you can add as many fields as you need to multiply together. Just add the field names in quotes, separated by a comma...

Ariel

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators