Getting Started with Expressions

Modified on Thu, Apr 6, 2023 at 7:43 PM

The Practice Expression Screen

The best way to go through this guide is to do it interactively using the Practice Expressions screen in the Reports module as shown below.

Hello World

To get started, enter the phrase Hello World into the Expression field and then click the Evaluate Expression button.

The result of an expression is expressed in the boxed area.  In this case, the type of output from the expression is a String.

Strings

A string is a collection of characters that are linked together (imagine the picture below) that may form any kind of output.  There is no limit to the number of characters that can be put onto a string.  Just about any text you place into the expression field will be echoed back as a String. 

Doing some basic math

Expressions can do more than just echo text back as a string.   Expressions can output the result of math operations.   To try this out type 1 + 1 into the expression field and then click the Evaluate Expression button.   

You were probably expecting to see the number 2 to be outputted but instead you are looking at 1 +1 outputted as type String.    By default an Expression will just echo anything you key into the box back to your screen.   We need a way to tell the Expression engine to evaluate our math problem.    

Expression Markers ${ }

To do this you surround the math problem with Expression markers.   Type ${ 1 + 1 } into the expression field and then click the Evaluate Expression button.   Anything between ${ and } will be computed and displayed.  You will notice that the output is now 2 and the type is Long.

Integer Numbers

There are 2 types of whole numbers that can be returned in Expressions:  An Integer and a Long.    They will never have a decimal point.

Longs

A Long integer is a whole number with a value between -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.     Because Longs can hold such large numbers it is the default return type for most integer math operations.

Integers

In the Expression Language, an Integer is a whole with a value between -2,147,483,648 through 2,147,483,647.

String Literals

A string literal is any text that is not inside of Expression Markers.  In the first example we entered Hello World by itself.  That is a String literal.   We can mix string literals with Expression Markers to build new Strings of output.  To try this out enter 1 + 1 is ${1 + 1} into the Expression box and click the Evaluate Expression button.

You will see the phrase 1 + 1 is 2 in the output box with a return type of String (not Long, more on this later).

You can also use several sets of expression markers in an expression.  For example:

1 + 1 is ${1+1} and 2 + 2 is ${2+ 2}. 

Doubles

Double and Floats are floating point numbers (numbers with decimals) that are not exact but approximations of a real number.   Double and floats are a type of output we want to avoid at all costs but are easily introduced by accident.   Here we will demonstrate why we do not want to ever user these types.

Let’s start with the expression the ${1.1 + 1.1}.   The output as expected is 2.2 with a type of Double.   AS you can see the Expression Engine will automatically convert any numbers with a decimal to type Double (something we actually do not ever want to do).   You might be thinking at this point “I don’t see the problem”.   To see it all fall apart, enter the expression ${1.1 + 1.1 + 1.1}.   I’m sure you were probably expecting to see the output as 3.3, but instead got something like 3.3000000000000003.  You will notice that the answers are sometimes correct and sometimes not.   This is why we want to avoid using Doubles ever in any of our calculations, especially money.  

We will revisit decimal numbers later on, but for now know that if you have an output of type Double, you are most likely going to have some subtle problems.

Formatting Output

What if wanted to the output of our numbers to have some formatting rules applied?  For example, what if I wanted the output of 1+ 1 to be formatted with 2 leading zeros.    You do this with the format output box.    There are a couple of rules with the format output box that should be known.    The format (output) box only formats Numbers, Booleans (True or False) and Dates and will always return as a String. 

Concatenating Strings

You can also use String literals inside of the Expression Markers.   This will seem like an odd way to display text but its usefulness will become obvious later when we start manipulating text fields from the database.  For now, let’s just explore a simple concatenation of strings.  

${ ‘Hello World’ } will output Hello World as a String.    You can also combine strings together with the += operator.  So ${‘Hello ‘ += ‘World’} will also output Hello World as a String.

Outputting data from SchoolFi

Any screen in SchoolFi that lets you build an expression will have an icon that opens a pop up dialog box called the Expression Builder.   This dialog box will show you the types of information you can display in the Expression.    On the practice expression screen the dialog should look something this:

 

Date and Times

The Expression Builder shows us some really useful variables that we can use.  A variable name is replaced with its value when used inside of Expression Markers.  For example I can create an expression that outputs today's date like this:

Today is ${today}

The output should be something like “Today is 08/23/2015” of type String.   If you try to use formatting on it you will notice it will not do anything.   If you remember from above you can only format Numbers, Dates and Booleans.  So let’s try to output todays date as a Date type.     

Today is ${today_raw}

You should now see “Today is Sun Aug 23 00:00:00 EDT 2015”.

The default output for a Date is pretty unfriendly.  Now we can use the format box to make it more useful.   Enter M/dd/yyyy into the format output box and re-evaluate.   The output now should be 8/23/2015 as type String.   The format is CASE SENSITIVE.   A lower case m will not give what you expect in the month column.

Notice how the date above has the time midnight in it.  This is because the Date type is really a Date and Time type.   A specific date is represented in the system as midnight.

Beans / Objects

One of the variables that is almost always available in an expression is Staff.  On the Practice Expression screen the staff member in that variable is you; the user that is logged in.   The type of Object is Staff but you will notice that it is also called a Bean instead of a primitive.  A Bean is the word chose by marketing of the Java programming language when referring to an Object.  (Get it… Beans are used to make Java / Coffee…..)  A bean or object is one piece of complex data stored in School Fi that has many properties (or fields) on it that can be used in an expression.     Each field in a bean is usually a primitive type (Date, Long etc…). 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article