Report on function fields
Summarize
Summary of Report on function fields
Function fields in ServiceNow display computed results derived from database queries rather than storing static values. These fields calculate their values based on other fields and constants, making them usable in reports and data visualizations like regular fields. Management of function fields—creating, editing, and deactivating—is assigned to users with thefunctionfieldadminrole, which must be granted by an admin after upgrades.
Show less
Function field operations
Function fields support a variety of operations using the glidefunction:<operation> syntax, allowing dynamic data calculations within reports. Key operations include:
- add(), subtract(), multiply(), divide(): Perform arithmetic on number fields or constants, returning numerical results.
- concat(): Combines multiple fields or constants into a single string for text concatenation.
- datediff(): Calculates duration between two date/time fields, returning the difference as a duration.
- dayofweek(): Returns the day of the week as an integer, with flexibility for week start day.
- length(): Computes the character length of a string field.
- coalesce(): Returns the first non-empty value from multiple fields.
- position(): Finds the position of a substring within another string, optionally starting at a given index.
- substring(): Extracts a substring from a string field based on start position and length.
Constants used in operations should be enclosed in single or double quotes.
Configuring function fields
ServiceNow allows configuring up to 20 active function fields per table via the Report Designer. These fields enable grouping and stacking reports by function results.
- Create: Define new function fields to enhance report grouping and visualization.
- Edit: Users with the creator, admin, or functionfieldadmin roles can modify function field definitions, except for labels and return types.
- Deactivate: Function fields can be deactivated by their creator or admins to manage the active field limit.
- Delete: Admins can delete function fields, useful for reusing field names.
- Disable creation: System properties can be configured to disable function field creation in the Report Designer.
Managing function fields effectively enables ServiceNow customers to create dynamic, calculated data visualizations and reports based on their unique business logic and data relationships.
While regular fields store a value in the database, a function field displays the results of a database query. The function field generates the value based on computations of other fields and constants. You can use these fields in reports and data visualizations as you would other fields.
The responsibility for creating, editing, and deactivating function fields belongs to the user with the role function_field_admin. On upgrade, no user has this role. An admin must give this role to a non-admin user. See Create a role.
Learn about function fields here: Function field.
Function field operations
| Operation | Description | Example |
|---|---|---|
| add() | Takes two number fields as input, adds them, and returns
the results as a field value. This function also takes numerical values for either input. Place numerical values in single or double quotation marks. |
glidefunction:add(child_incidents, parent_incident)
Returns 6 if the incident has five child incidents and one parent incident. Possible return types: Decimal, Floating Point Number, Large Whole Number, Whole Number |
| subtract() | Takes two number fields as input, subtracts the second from the first, and returns the result as a field value. This function also takes numerical values for either input. Place numerical values in single or double quotation marks. |
glidefunction:subtract(u_num1, u_num2)
Returns 2 if num1 = 8 and num_2 = 6. Possible return types: Decimal, Floating Point Number, Large Whole Number, Whole Number |
| multiply() | Takes two number fields as input, performs the
multiplication, and returns the results as a field value. This function also takes numerical values for either input. Place numerical values in single or double quotation marks. |
glidefunction:multiply(u_num1, u_num2)
Returns 48 if num1 = 8 and num_2 = 6. Possible return types: Decimal, Floating Point Number, Large Whole Number, Whole Number |
| divide() | Takes two number fields as input, divides the first by the second, and returns the result as a field value. This function also takes numerical values for either input. Place numerical values in single or double quotation marks. |
glidefunction:divide(u_num2,u_num1)
Returns 5 if num2 = 10 and num1 = 2. Possible return types: Decimal, Floating Point Number, Large Whole Number, Whole Number |
| concat() | Takes any number of comma-separated fields and constants as input, concatenates the input, and returns a single string as a field value. | glidefunction:concat(incident_number, '/', short_description)
Returns "INC0001 / My client needs a new laptop." if the value of the number field is 'INC0001' and the short_description is 'My client needs a new laptop'. Return type: Text |
| datediff() | Takes two date/time fields as input, calculates the difference between the dates in days, minutes, and seconds, and returns the results as a duration field value. | glidefunction:datediff(closed_at, sys_created_on)
Returns the duration of an incident from the creation date to the close date. Example result: 10 days, 8 hours 23 minutes 11 seconds Return type: Duration |
| dayofweek() | Takes two arguments: A date field and a constant of either '1' (week starts on Sunday) or '2' (week starts on Monday). Returns the results as an
integer value that represents the day of the week. The dayofweek() function uses UTC dates, but adjusts comparison values based on the instance's time zone. |
glidefunction:dayofweek(resolved_at, '1'). If resolved_at occurs on a Wednesday, returns 4 if the integer is 1 and returns 3 if the integer is 2. Return type: Whole number |
| length() | Takes a string field as input, calculates the field length in characters, and returns the results as a field value. | glidefunction:length(short_description)
Returns 37 if short_description = "This application is performing a test". Return type: Whole number |
| coalesce() | Takes any number of comma-separated fields as input and returns the first non-empty value. | glidefunction:coalesce(closed_at, resolved_at, sys_updated_on)
If the value of closed_at is empty, the function returns the value of resolved_at. If the value of resolved_at is also empty, the function returns the value of sys_updated_on. Return type: Text |
| position() | Takes two text fields or two text fields and a whole number as input. One or both of the text fields can also be strings.
Returns 0 if the first text field is not present in the second (after the position of the whole number if specified). |
Return type: Whole number |
| substring() | Takes a text field and two whole numbers as input. Returns the first instance of a string that starts at the position of the first whole number and is the length of the second. | glidefunction:substring(short_description, '7', '2')
If the value of the short_description field is 'We're going to the store', returns 'go'. Return type: Text |