TrackStudio 3.0 Documentation
Scripts

This topic describes how to use scripts in calculated custom fields to customize filters, reports and email notification rules. (User Management->Scripts tab).

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. (ie. such as, 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.*

In TrackStudio Enterprise you can use any classes in your expressions (including you own). To do that, you should change the class gran.tools.ShellClassLoader and add the classes and packages that you need. 

Calculated custom fields and static fields can be created for tasks, users and workflows by using different sets of variables. 

 

For instance, let us create a custom field that will return the number of days since the last update (this field can be used to find out what tasks have been neglected for a long time). 

1. Go the the User Management->Scripts tab. 

2. Create the task processing script Neglected tasks. 

3. Go the the User Management->Scripts->Edit tab. 

4. Click the icon f(x) to create an expression. 

5. In the left-hand part of the popup window open the Variables folder, and select task->getUpdatedate()

6. You should get the present time in milliseconds and subtract task update date from it. That should give you the following expression:

(new Date()).getTime() - task.getUpdatedate().getTime()

7. Now you have the difference between the present time and the date of the task update in milliseconds. To convert this number to days, you should modify expression to the following one

((new Date()).getTime() - task.getUpdatedate().getTime())/DAYS

8. Press the Check button. The expression should be correct. 

9. Save the expression using the Save button. 

10. Go to the Task Management->Task->Customize tab. 

11. Specify Caption for the custom field: since

12. Select the field type: Integer 

13. Specify the formula: Neglected tasks 

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

new Date(milliseconds)

Special attention should be paid to the List data type. List is a set of values. In a static custom field you choose one of these values and set it. In calculated fields you should first specify the set of values as usual and then specify the expression which will return the result that exactly matches one of the values (not the keys) from the list. 

For example, to create a script that will return the day of the week on which an issue was created. 

1. Go the the User Management->Scripts tab. 

2. Create the task processing script Weekday. 

3. Go the the User Management->Scripts->Edit tab. 

4. Click the icon f(x) to create an expression.

Calendar ca = Calendar.getInstance();
ca.setTime(new Date(task.getSubmitdate().getTime()));
int day = ca.get(Calendar.DAY_OF_WEEK);
switch (day){
     case Calendar.SUNDAY: return "Sunday";
     case Calendar.MONDAY: return "Monday";
     case Calendar.TUESDAY: return "Tuesday";
     case Calendar.WEDNESDAY: return "Wednesday";
     case Calendar.THURSDAY: return "Thursday";
     case Calendar.FRIDAY: return "Friday";
     case Calendar.SATURDAY: return "Saturday";
}
return null;

5. Press the Check button. The expression should be correct. 

6. Save the expression using the Save button. 

7. Go to the Task->Customize tab. 

8. Enter Caption for the custom field: weekday

9. Specify the formula: Weekday 

10. Select the field type: List

11. Specify the list of possible values. Enter only one value at a time: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday.

You are here: User Management > Scripts
Copyright (c) 2002-2004. TrackStudio, Ltd. All rights reserved.