Expression Fields
You can create custom export fields using Expression Fields. Expression fields allow you to access and combine a large number of variables for export using simple JavaScript syntax. For instance, you can combine RT and OT using an expression such as:
{TimeEntry.payCode1}+{TimeEntry.payCode2}
Or you could combine the customer, project and task names into one field:
{TimeEntry.customerId.name}+"."+{TimeEntry.projectId.name}+"."+{TimeEntry.taskId.name}
Expressions must evaluate to either a number or string (text) value, as per the usual rules of JavaScript. For instance, the following expression would evaluate to a number:
{TimeEntry.hours}+100
But the following expression would evaluate to a string:
{TimeEntry.hours}+" hours"
Note 1: null variable values will be converted to a blank value if the variable type is string, or to zero if the variable type is a number. |
Comparisons and Logical Operations
You can use JavaScript comparison and conditional operators. For example, you could output an employee custom field value depending upon a pay code ID:
if ({TimeEntry.payCodeId.uid}=="maternity")
{TimeEntry.userId.xMaternityAccount};
else
"";
You can also compare numeric values:
if ({TimeEntry.hours}>8.0)
"OT";
else
"RT";
Note 2: You should not use the "return" JavaScript keyword. Instead, the expression should just evaluate to a single value. |
Debugging Scripting Errors
If your expression has a syntax error then the cause will outputted to the export file (as a string). Even if the syntax is correct, you could encounter errors in the evaluated expression if your data is not valid (for example, you divide by zero). You will want to put any proper checks in place in the expression to avoid this (you can even use try/catch exception handling if warranted).
Time Entry Export Variables
Here is a partial list of variables you can refer to in your expression. Note that all variables must be enclosed in "{" and "}".
Variable |
Data Type |
Description |
{TimeEntry.date} |
Date |
Date of time entry. Note that you can control the formatting of this using a pattern argument - see the section below on Date Formatting. |
{TimeEntry.start} |
Date-time |
Date and time of start of time entry. Note that you can control the formatting of this using a pattern argument - see the section below on Date Formatting. |
{TimeEntry.finish} |
Date-time |
Date and time of finish of time entry. Note that you can control the formatting of this using a pattern argument - see the section below on Date Formatting. |
{TimeEntry.hours} |
Numeric |
Total hours for time entry. |
{TimeEntry.type} |
Text |
Type of time entry, either 'Work' or 'Leave'. |
{TimeEntry.workHours} |
Numeric |
Same as hours if type is 'Work', zero otherwise. |
{TimeEntry.leaveHours} |
Numeric |
Same as hours if type is 'Leave', zero otherwise. |
{TimeEntry.payCode1} |
Numeric |
Regular hours. |
{TimeEntry.payCode2} |
Numeric |
Overtime hours. |
{TimeEntry.payCode3} |
Numeric |
Double-time hours. |
{TimeEntry.payCode4} |
Numeric |
Triple-time hours. |
{TimeEntry.userId.fullName} |
Text |
Full name (last, first) of employee for this entry. You can also use the alias {User.fullName}. |
{TimeEntry.userId.uid} |
Text |
ID of employee for this entry. You can also use the alias {User.uid}. |
{TimeEntry.userId.login} |
Text |
Login name of employee for this entry. You can also use the alias {User.login}. |
{TimeEntry.groupId.name} |
Text |
Name of group (department/crew) for this entry. You can also use the alias {Group.name}. |
{TimeEntry.groupId.uid} |
Text |
ID of group (department/crew) for this entry. You can also use the alias {Group.uid}. |
{TimeEntry.payCodeId.name} |
Text |
ID of pay code for this entry. You can also use the alias {PayCode.name}. |
{TimeEntry.payCodeId.uid} |
Text |
ID of pay code for this entry. You can also use the alias {PayCode.uid}. |
{TimeEntry.customerId.name} |
Text |
Name of customer for this entry. You can also use the alias {Customer.name}. |
{TimeEntry.customerId.uid} |
Text |
ID of customer for this entry. You can also use the alias {Customer.uid}. |
{TimeEntry.projectGroupId.name} |
Text |
Name of project group for this entry. You can also use the alias {ProjectGroup.name}. |
{TimeEntry.projectGroupId.uid} |
Text |
ID of project group for this entry. You can also use the alias {ProjectGroup.uid}. |
{TimeEntry.projectId.name} |
Text |
Name of project for this entry. You can also use the alias {Project.name}. |
{TimeEntry.projectId.uid} |
Text |
ID of project for this entry. You can also use the alias {Project.uid}. |
{TimeEntry.taskGroupId.name} |
Text |
Name of task group for this entry. You can also use the alias {TaskGroup.name}. |
{TimeEntry.taskGroupId.uid} |
Text |
ID of task group for this entry. You can also use the alias {TaskGroup.uid}. |
{TimeEntry.taskId.name} |
Text |
Name of task for this entry. You can also use the alias {Task.name}. |
{TimeEntry.taskId.uid} |
Text |
ID of task for this entry. You can also use the alias {Task.uid}. |
You may also refer to any object's custom fields, using the appropriate variable name. For example, the "Maternity Account" custom field on an employee object would have a variable name like this:
{TimeEntry.userId.xMaternityAccount}
You can get the variable name of any custom field from the custom field properties page for the appropriate object.
Time Sheet Export Variables
Variable |
Data Type |
Description |
{TimeSheet.start} |
Date-time |
Date and time of start of sheet period for the time entry being exported. Note that you can control the formatting of this using a pattern argument - see the section below on Date Formatting. |
{TimeSheet.finish} |
Date-time |
Date and time of finish of time sheet period for the time entry being exported. Note that you can control the formatting of this using a pattern argument - see the section below on Date Formatting. |
Aliases
Many expression variables can be replaced with shortcuts or aliases. For example, TimeEntry.projectId.uid can be replaced with Project.uid, or TimeEntry.userId.fullName can be replaced with User.fullName. You will want to use the full expression variable name when there is ambiguity about which field to refer to. For example, to get the full name of the user who submitted the time you would use TimeEntry.lockerId.fullName, or to get the full name of the first approver you would use TimeEntry.apprv1Id.fullName.
Date Formatting
You can control the formatting of dates, times and date-times by adding a date format pattern as an argument to the variable. The format of this pattern is the Java Simple Date Format Pattern, described here:
https://docs.oracle.com/javase/10/docs/api/java/text/SimpleDateFormat.html
If you want to format a date variable you would add a date pattern argument after the variable name. For instance, to format a date variable as YYYY-MM-DD you would do the following:
{TimeEntry.start,yyyy-MM-dd}
The date pattern argument follows a comma after the name of the variable. Make sure the argument is contained within the '}', and you cannot use the '{', '}' or ',' characters in date patterns.