Expression Language in the Genesis SIS
Expression Language is a way to access and manipulate data for inclusion in various areas of Genesis:
- Result Views - It is used for specifying what data goes into columns in a ResultView and for manipulating data in those columns.
- ReportWriter - It is used for creating Columns in the ReportWriter that can access and manipulate data that exists in other columns of the report.
- Searching - Included as search parameters in various search screens, such as Student Search and Curriculum Search
This article discusses what Expression Language is and How It Can be Used in the ReportWriter.
Expression Language for the Report Writer
Expression Language is what you use to create the Expressions in Expression Columns. An "Expression Column" is a text field that can contain Expressions and/or literal text.
Here is a perfectly fine Expression Column that simply contains the literal text "HELLO WORLD" - and will print exactly that in each and every row:
Here is another Expression Column that contains a mixture of literal text and Expressions:
- Literal text is any character or characters that is outside of ${ } curly brackets. It can be as simply as a single blank space.
- Expressions are anything found between a ${ open sequence and a } closing sequence. ${ expression-stuff } There can be any number of individual Expressions in an Expression Column.
What is Expression Language?
Expression Language is created by Genesis, and allows 'building' of macros for data querying. Although much of the grammar is adopted from Java language, the expressions are a Genesis language.
In the Genesis ReportWriter, Expression Language is a “language” for expressing:
- How to create columns from other columns, parameters and calculations.
- How to make choices about what should be printed in a column.
- How to create filters to determine whether a row should be included in a report or a form should be printed as part of a report.
- How to process parameters to make decisions about what data a report should include.
How to Get Started
It is important that you understand how & when Expression Language fits into the ReportWriter.
Please read the READ FIRST: The Column Processing Model for Expression Processing article before continuing here. This will explain a bit more about how Expression Language fits into the ReportWriter and how it can be used to create more powerful reports.
How are Expression Processed
"Expression Columns" in the ReportWriter are text fields that can contain expressions as well as simple straightforward literal text. The literal text - which can be as simple as a single blank character - does two things:
- It gets placed into the output exactly as is. E.g. a blank is a blank (that is, a space) in the output, A newline character is output as a newline character: (actually, strictly speaking, as two characters: line feed or 'move to the next line' and carriage return or 'go back to the starting point of the line') - Newline generates a move to the start of the next line.
- Literal text of any type - even a single space - turns the entire Expression into a String. Thus an unseen blank character after the end of an expression causes the entire value to be a String (even if you were hoping for something else).
The following diagram illustrates how expression text field's text is processed as an Expression:
What can be done with Expression Language that couldn’t be done before?
- Separate the data you extract from the Genesis database from the decisions you make about how to use it and how to format it for output.
- Truly transform data extracted from the database into what you wish to print on or in a report
- Concatenate data from multiple ‘data’ Columns into a single ‘Print’ Column
Concatenation: Putting Multiple Strings Together
- Convert bits of text from one form into another. For example, convert ‘F’ into “Free” in the same column in which ‘R’ is converted to “Reduced”.
- Perform arithmetic computations Arithmetic in Expression Language
- Perform date computations Working with Dates in Expression Language
- Format Strings for output
- Make complex decisions about which rows of data to print.
Conditional Expressions - Decisions in Expression Language
- Make decisions about how many forms to generate.
- Compare the previous row of output with the current row in order to decide whether or not to do something.
- Build tests directly into column calculations
Conditional Expressions - Decisions in Expression Language
- Insert ‘counters’ and other complex computations into the report
- Print ‘summary’ Columns. Technique: Compressing Multiple Rows for a Student into a Single Row
How to Use the Expression Language Articles
The articles in this section introduce you to the features and functions of the Expression Language and to the techniques you can use them for.
Expression Language is Very Flexible
The Expression Language itself is very powerful and flexible. “Expression Language” is what can occur between the “${“ open bracket and “}” close bracket. What can occur there includes the following:
- References to columns preceding the current Expression column in the list of columns:
- Columns in the next row of output are referenced by saying ‘nextRow.column’. E.g. ${nextRow.studentName}, ${nextRow.gender}, ${nextRow.dateOfBirth}.
- Columns in the previous row of the report are referenced by saying ‘prevRow.column’. E.g. ${prevRow.studentName}, ${prevRow.gender}, ${prevRow.dateOfBirth}.
- Parameters to the Report including both the built-in set of parameters and ‘user defined macros’ or parameters that you create on the Parameters tab of the Report. E.g. ${params.SchoolYear}.
- Literal strings. E.g. “Y”, “N”, “Daughter”, “Guardian 1”, etc.
- Literal numbers. Including:
- Integers 17 922019
- Decimal (floating point) numbers: 24.7 0.44
- Exponential numbers: 1.2E4 (1.2 * 10**4 or 12000)
- Built-In Functions: A number of functions are provided by the ReportWriter Expression language. These can all appear in expressions. E.g. ${rw:toUpperCase(row.studentName)}
- Expression Language Operators: All of the ‘operators’ listed in the table below, including:
- Conditional Expressions – “IF” statements that result in decisions being made within the column itself. See below the “Making Decisions in a Report” section.
- Logical operators - which are always true or false
- Relational operators - which are also always true or false
- Arithmetic operations – which always result in numeric values.
- But NOT Dates: Dates cannot be input directly. E.g. 12/24/2011 becomes a STRING, not a DATE. Dates must be converted from Strings to an actual DATE via the ‘toDate’ Function. See below.
The full list of operators, values and functions that can appear in ‘expressions’ is below:
Expression Language Operators, Functions & Values | Examples | ||
Arithmetic Operators | |||
+ | Add | ||
- | Subtract | ||
* | Multiply | ||
/ | Divide | ||
% | Modulo (integer remainder) – Finds the remainder | 10%4 = 2 | |
Logical Operators | |||
! | Not - unary ‘not’ operator. Reverses the truth of a test value. | !A or !empty | |
|| | Or - A || B means ‘A or B’ – Either A or B must be true | A || B | |
&& | And - A && B means ‘A and B’ must both be true | A && B | |
Relational Operators | |||
== | Equal to | A == B or A eq B | |
!= | Not equal to | A != B or A ne B | |
< | Less than | A < B or A lt B | |
<= | Less than or equal to | A <= B or A le B | |
> | Greater than | A > B or A gt B | |
>= | Greater than or equal to | A >= B or A ge B | |
String compare functions | |||
Contains | Test whether the column “contains” a certain String. Returns true/false. | rw:contains() | |
startsWith | Test whether the column “starts with” a certain String. Returns true/false. | rw:startsWith() | |
endsWith | Test whether the column “ends with” a certain String. Returns true/false. | rw:endsWith() | |
Date Compare | |||
dateCompare(date1, date2) | Returns an integer value: | rw:dateCompare(today, params.startDate) | |
Programmatic | |||
empty | Is the field empty? | ||
!empty | Does the field have something in it? (is it not empty?) | ||
Conditional Operator | |||
?: | A? B : C – If A, then B else C | ||
Special Values | |||
true | Logical “true”. “Y” to the ReportWriter | ||
false | Logical “false”. “N” to the ReportWriter | ||
null | “Empty” – for testing fields | ||
String Functions – These are provided to work with Strings | |||
toUpperCase | Convert String to all upper case | rw:toUpperCase( params.SCHOOL_NAME) | |
toLowerCase | Convert String to all lower case | rw:toLowerCase(row.emailAddr) | |
initCaps | Convert String to all lower case then capitalize the first letter of each word | rw:initCaps(row.lastName) | |
Replace | Replace one piece of text with another | re.replace(row.lunch,”F”,”Free”) | |
Date Functions – These are provided to work with Dates | |||
toDate | Convert a date String to an actual DATE. | rw:toDate(“07/24/2011”) | |
formatDate | ${rw:formatDate(value, pattern)} Converts date into a different date format | ${rw:formatDate(studentRegDate, MM/dd/yyyy)} | |
dateAddDays | Add X days to the startDate. X can be +- | rw:dateAddDays(row.aDate, -1) == yesterday | |
dateFindDayOfWeek | Find the “next X day” E.g. Find next Monday plus X weeks | rw:dateFindDay(today,”Mon”, 0) – Find next Monday | |
findCycleCode | Find the cycle of type type in which the Date falls, | rw:findCycleCode(today, params.SCHOOL_CODE, “Sports Season”) | |
getCycleStartDate | Find the first date in the cycle | rw:getCycleStartDate( params.SCHOOL_CODE, | |
getCycleEndDate | Find the last date in the cycle | rw:getCycleEndDate( params.SCHOOL_CODE, | |
getNumberOfDays | Get the number of days between two dates | rw:getNumberOfDays(fromDate,thruDate) | |
getDayOfYear | Get the numberical day of the year. E.g. Jan 24th is the 24th day of the year | rw:getDayOfYear(date) | |
Lookup Functions – Provided to lookup Descriptions for Generic Codes in Genesis | |||
getCodeDescription | Lookup a Generic Code’s Description | rw:getCodeDescription('LANGUAGE_CODE', row.homeLanguageCode) | |
Note: Clicking the fx button when working on an expression column will give you the full (updated) list of available expressions and functions:
How Technique: Compressing Multiple Rows for a Student into a Single Row
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article