TrackStudio 3.0 Documentation
Edit Scripts

This section describes how to set formula for scripts (User Management->Scripts->Edit).

You can specify an expression in the expressions editor. TrackStudio has a formula editor for editing expressions and checking syntax. For the task processing scripts specify the task number to calculate the expression. Click the f(x) icon to open the expression editor. 

 

When you click the Check button, the user processing scripts are executed for the script owner. Sometimes an expression correct for one task can be incorrect for another (for example, it can lead to dividing by zero). If the expression is incorrect or if the calculated value type does not match the field type, the result will be an empty field. 

In the left-hand section of the editor's window, you'll find a tree with available operations, variables, constants and functions. Left-click on a variable or a constant to add it to the expression. 

 

In the right-hand part of the window, you'll find a field where you can enter the expression and two buttons - Save and Check. The Check button will check the correctness of the expression by calculating it. The Save button will save the script. 

 

 

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 

The following sample script collects text of all messages for the current task:

String s = "";
for(Iterator it = task.getMessages().iterator(); it.hasNext();) {
    String desc = it.next().getDescription();
    if (desc != null) {
      s += desc + "<br>";
      s += "-------------------------------<br>";
    }
}
return s;

 

The following sample script calculates a summary of the actual budget for all not-closed tasks.

public double getAbudget(Object t) {
    double d = 0;
    if(t.getAbudget() != null && t.getClosedate() == null)
        d = t.getAbudget().doubleValue();
    for(Iterator it = t.getChildren().iterator(); it.hasNext();)
        d += getAbudget(it.next());
    return d;
}
return getAbudget(task);

 

The following script lists all custom fields with values for the current task:

String s = "";
Map udfs = task.getUDFValues();
for(Iterator it = udfs.keySet().iterator(); it.hasNext();) {
    Object udf = udfs.get(it.next());
    s += udf.getCaption() + ":<br>";
    s += udf.getValue(task) + "<br>";

}
return s;
Copyright (c) 2002-2004. TrackStudio, Ltd. All rights reserved.