Syntax, Operators, Functions

Syntax

Formula fields can either be

  • Expressions as  ${me.budget * 0.10} where me is the project 
  • contains a mix of expression and text as follows: The Project ${me.name} was created on ${me.created}.
    This will print the output as : The Project Sample Project - Office Setup was created on Thu Jun 20 08:30:16 EDT 2013.
  • contain a mix of expression and text as in <a href="http://mywikiserver/project/${me.id}>Wiki Link</a>
    This will print Wiki Link as the output which is hyperlinked with the link substituted with the entity's ID.


When formulas are evaluated, anything enclosed in ${ }is treated as an expression and evaluated. Everything outside it is copied to the output verbatim as is.
${me.budget} will display the budget of the entity.
{me.name} will be printed as {me.name} in your report or the details page.

You can also use conditional logic in the formula.


Operators and Literals

In addition to the . and [] operators, the expression language provides the following operators:

  • Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)
  • Logical: and, &&, or, ||, not, !
  • Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. 
    Comparisons can be made against other values, or against boolean, string, integer, or floating point literals.
  • Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.
  • .after, .before, .equal: Date comparison operators.

The precedence of operators highest to lowest, left to right is as follows:

[] .
() - Used to change the precedence of operators.
- (unary) not ! empty
* / div % mod
+ - (binary)
< > <= >= lt gt le ge
== != eq ne
&& and
|| or
? :

Some Examples:

Formula
Output
${5 + 3}8
${5 - 3}2
${5 / 3}1.67
${5 * 3}15
${5 % 3}2
${5 > 3} or ${5 gt 3}Yes
${5 >= 5} or ${5 >= 5}Yes
${5 < 3} or ${5 lt 3}No
${5 <= 5} or ${5 le 3}Yes

Literals

The JSP expression language defines the following literals:

Boolean: true and false. For example, ${me.critical == true}, where me is a task
String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\.
Null: null

Functions

A few predefined functions are also available as stated below:

Variable
Usage
Description
formatDate${formatDate(me.start)}Prints a project date as per the format specified in the viewer's preferences.
Date.format${Date.format(me.startCalendar, "MM-MMMM")}Prints the Month of project's start date. 11-November
formatDateTime${formatDateTime(me.start)}Prints project date and time as per viewer's preferences.
formatCurrency${formatCurrency(me.budget)}Prints a currency field prefixed with the currency symbol as specified in the company profile.
formatNumber${formatNumber(me.bcws)}Prints a number as per the viewer's locale. Especially useful when printing floating pointing number.
hoursToHHMM${hoursToHHMM(me.estimatedHours)}Prints hours in the form HH:MM. For example, ${hoursToHHMM(3.5)} will print 3:30
ceil${ceil(5.3)}Returns the nearest integer larger than the input. For example ${ceil(5.3)} will return 6
floor${floor(4.8)}Returns the nearest integer smaller than the input. For example ${floor(4.8)} will return 4
abs${abs(-3.2)}Returns the absolute value of a number. For example ${abs(-3.2)} will return 3.2
round${round(3.6)}Returns the rounded value of input. For example ${round(3.6)} will return 4
Date.now()${Date.now()}Prints today's date.
me.created${me.created}Prints the created date of the entity. For e.g, the date when a project was created.
Date.addDays(Date, days) ${Date.addDays(me.Create_Invoice_Date, 30)}Prints the date after adding the entered days. For example, Create_Invoice_Date is a custom field having a date 13-Oct-2015. So adding 30 days will result in 13-Nov-2015.
.before
.after
.equal 
${me.New_DueDate).after(me.completed) : 'OnTime' ? 'Delayed'}Prints On Time or Delayed after comparing first date with second.
Date.isoToDate('date') Date.isoToDate('2016-12-01') Displays date as per your Display date format.