TrackStudio 3.0 Documentation
Example

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.