TrackStudio Enterprise 3.1
Script Concepts

Script represents a description on the Java-like language of the calculated custom field algorithm.

To create a calculated custom field, you should create a static (non-calculated) custom field and then specify a script for it. If a custom field has no script, it is considered static. So, if you delete the expression from a script, all custom fields that use it become static. No results is saved to the database for a calculated field. 

TrackStudio uses Java-like language based on BeanShell to evaluate expressions. It means that you can create not only basic mathematical expressions, but also more complex expressions (if, for, or while). You can also use some Java classes. For security reasons you can only use following classes in your expressions:

java.lang.Boolean
java.lang.Byte
java.lang.Character
java.lang.Class
java.lang.Comparable
java.lang.Double
java.lang.Float
java.lang.Integer
java.lang.Long
java.lang.Math
java.lang.Number
java.lang.Object
java.lang.Short
java.lang.String
java.lang.StrictMath
java.lang.StringBuffer
java.util.*
java.text.*
java.sql.Date
java.sql.Time
java.sql.Timestamp
gran.secured.*
gran.tools.Logger

To use any other classes in your expressions change the class gran.tools.ShellClassLoader and add the classes and packages that you need. If the expression is incorrect or if the calculated value type does not match the field type, the result will be an empty field (null). 

TrackStudio allows you to create calculated custom fields of the same types as static custom fields. (i.e. Integer, Float, String, Date, List, etc) You should ensure that the result matches the required type. For example, to get the result of date calculation in milliseconds (long), you should convert it to the Date type:

new Date(milliseconds)

You can use the following constants:

Constant 
Type 
Description 
DAYS 
long 
msec/day 
HOURS 
long 
msec/hour 
MINUTES 
long 
msec/minute 
SECONDS 
long 
msec/second 
Copyright (c) 2002-2005. All rights reserved.