9 Replies Latest reply on Jan 19, 2012 5:59 AM by thefiggs

# Custom Calculation Script

I am trying to create a custom script for this formula that I had in excel. ANY help is greatly appreciated.totally frustrated at this point........

=IF(P27 > 0,P27/(N27 * 0.1),0)

• ###### 1. Re: Custom Calculation Script

Assuming the names of the other fields are still "P27" and "N27", use this code as your custom calculation script:

var p27 = this.getField("P27").value;

var n27 = this.getField("N27").value;

if (p27!="" && p27>0 && n27!="" && n27!=0) {

event.value = p27 / ( n27 * 0.1);

} else event.value = 0;

(notice I've added the condition that N27 can't be empty or zero, eitherwise you'd get a division by zero, which is illegal)

• ###### 2. Re: Custom Calculation Script

THAT IS GREAT AND IT WORKED! Now I just need to round the number (i.e. instead of 45.7777777777 to  show 46)......THANKS

• ###### 3. Re: Custom Calculation Script

Change this:

event.value = p27 / ( n27 * 0.1);

To this:

event.value = Math.round(p27 / ( n27 * 0.1));

• ###### 4. Re: Custom Calculation Script

Okay,maybe this is easier to understand

first column is called      W

Second column is called S

Third column is called      T (the total for that row W * S )

At the end of my colums I have the Totals for column W, S, and T

then I have an overall score (which is what I need rounded) and that formula in excell is

=IF(T36 > 0,T36/(W36 * 0.1),0)

What I get is a plus at the end of my number.......

Message was edited by: thefiggs

• ###### 5. Re: Custom Calculation Script

The code I provided will round the result to the nearest integer.

• ###### 6. Re: Custom Calculation Script

Okay, i found what happened and it works like a charm now.  On the next script I did I get this eror

SyntaxError: missing ; before statement 1: at line 2

• ###### 7. Re: Custom Calculation Script

First off let me say I rreeeaalllly appreciate your help.  This is the script that i keep getting that error "SyntaxError: missing ; before statement 1: at line 2 " on

var CWTotalsWeight&Score = this.getField("CWTotalsWeight&Score").value;

var CWWeightTotals = this.getField("CWWeightTotals").value;

if (CWTotalsWeight&Score!="" && CWTotalsWeight&Score>0&&CWWeightTotals!="" &&CWWeightTotals!=0){event.value =Math.round(CWTotalsWeight&Score/(CWWeightTotals * 0.1));

} else event.value = 0;

• ###### 8. Re: Custom Calculation Script

You can't use an ampersand in the name of a variable.