How to Use Calculated Form Fields

If your questions are not answered on this page, please contact us.

Creating a Calculated Form Field

To create a calculated form field, create or edit a form type on the Greyswift configuration tab and click the "Calculated" button to insert a new calculated field into your form. You will notice that this new form field has a a data type of "Calculated Decimal" and an expression that you can define by clicking the "Edit Expression" button. That button will open the Edit Expression dialog where you can define an expression for your new calculated field.

Writing an Expression

The Edit Expression dialog enables you to easily build your expression using the helpful buttons for all available inputs and the most common operators. Clicking the buttons will automatically insert the specified operator or variable at the currently selected position in the "Expression Text" text box. You can also manually type any of these operators or variables into the text box as well as a variety of other more advanced operators and functions (see Further Reading below). To manually type in a variable, use square brackets as follows:

Parameter Type Usage
Current value of a form field
[Field:Field Name]
Previous value of a form field
[PrevField:Field Name]
Current value of a property
[Property:Property Name]

When you're finished, you can use the test inputs on right side of the Edit Expression dialog to verify that your expression is working as intended. Note that the expression must return a decimal number, and only numeric and date data types can be used as variables.


A possible expression for a field named "Tank Volume" might be:

3.142 * ([Property:Tank Diameter] / 2) * ([Property:Tank Diameter] / 2) * [Field:Liquid Level]

Calculated Date Form Fields

Greyswift also supports calculated date form fields. You can create a calculated date field by changing the data type of your calculated field to "Calculated Date". Everything else works the same as for a calcualted decimal field, except your field's expression must return a date value for the result to be valid. There are currently four supported date functions that you can use in your expression:

Function Description Usage
CurrentDate Returns the current date.
DatePart Takes one date parameter and one time unit parameter. The time unit specifies which part of the date this function will return.
DatePart(date, timeUnit)
DateAdd Adds the specified amount of time to the date parameter and returns the result.
DateAdd(date, timeValue, timeUnit)
DateDiff Computes the difference between two specified dates and returns the result in the specified unit of time.
DateDiff(timeUnit, startDate, endDate)

The time unit for the above functions is simply an integer that specifies a unit of time. The values are defined as follows:

  • 0, Millisecond
  • 1, Second
  • 2, Minute
  • 3, Hour
  • 4, Day
  • 5, Month
  • 6, Year

Date Examples

This expression will return the number of days that have elapsed since the last inspection.

DateDiff(4, [Field:Inspection Date], CurrentDate())

And here is another expression that will compute when the next inspection should be performed if inspections are performed on a monthly basis.

DateAdd([Field:Inspection Date], 1, 5)

Further Reading

Greyswift's calculated form fields are based on the NCalc expression evaluation library. For more information about this library, including a comprehensive list of supported operators and built-in functions, see the NCalc GitHub wiki.

For any further questions regarding calculated form fields or for assistance configuring your forms, please don't hesitate to contact us.