JavaScript

Currently Being Moderated

3 Step Formula

May 2, 2012 12:02 PM

Hello,

When using Adobe X Standard to write formulas in the Custom Calculation Script field, can you create a 3 step formula? Basically I want for it to be v1+v2-v3=v4.

Replies
• Currently Being Moderated
May 2, 2012 12:06 PM   in reply to a.n.bentz

You can have as many steps as you'd like. If those are your fields' names,

just place this formula under the Simple Field Notation option of the

Calculate tab of v4:

v1 + v2 - v3

|
Mark as:
• Currently Being Moderated
May 2, 2012 12:19 PM   in reply to a.n.bentz

As noted the simplified field notation is easy if the names comply with the naming requirements for this calculation.

You can even use the option for the "Field is the ____ of the following fields" by selecting the operation and fields to be processed.

If you want to use the Custom JavaScript Calculation then you need to write the calculation using JavaScript. This is approach is needed to use execution flow control statements like the "if...then...", use the methods of objects or call predefined functions.

To add 3 fields and prevent concatenation due to a blank field:

event.value = Number(this.getField("v1").value) + Number(this.getField("v2").value) + Number(this.getField("v3").value);

|
Mark as:
• Currently Being Moderated
May 2, 2012 12:57 PM   in reply to a.n.bentz

You can specify the number of decimals for the "Number" format. Setting the "Decimals" to 2 will round up at 0.50 or greater and truncate for values below.

If you want the value of the field to be rounded, then you need to use the custom JavaScript calculation and use the 'util.printf" method or write a function to perform the task. JavaScript's "Math.round" method has a known issue.

To get both the rounding and the decimal alignment:

var v1 = Number(this.getField("v1").value);

var v2 = Number(this.getField("v2").value);

var v3 = Number(this.getField("v3").value);

var nResult = v1 + v2 - v3;

console.show();

console.clear();

console.println("nResult = " + nResult);

var sResult = util.printf("%,0 .0f", result)

console.println("sResult = " + sResult);

console.println("event.value = " + Number(sResult))

event.value = Number(sResult);

|
Mark as:
• Currently Being Moderated
May 2, 2012 1:37 PM   in reply to a.n.bentz

The line to create the sResult variable should read:

var sResult = util.printf("%,0 .0f", nResult)

an not:

var sResult = util.printf("%,0 .0f", result)

The message references line 8 in the script and that there is no defined variable "reslut".

|
Mark as:
• Currently Being Moderated
May 2, 2012 2:23 PM   in reply to a.n.bentz

Sorry,

var sResult = util.printf("%,3 .0f", nResult);

This will create a number string with only the decimal point.

|
Mark as:
• Currently Being Moderated
May 3, 2012 7:17 AM   in reply to a.n.bentz

You can use the Math.floor() method:

eventn.vlaue = Math.floor(nResult);

or parseInt() global object:

event.value = parseInt(nResult, 10);

|
Mark as:
Actions

More Like This

• Retrieving data ...