Function field
-
- UpdatedAug 3, 2023
- 8 minutes to read
- Vancouver
- Platform Field Administration
Create function fields and scripts in the Now Platform to perform common database transformations and calculations.
Regular fields store a value in the database. Instead of storing data, a function field displays the results of a database query. Function fields do not have an associated database column. Instead, function fields generate a value based on simple computations of other fields and constants. They can be used like any other fields in the system: in forms, lists, query conditions, reports, and so on.
Example: Use case
You want to identify all incidents with a probably useless short description of fewer than 10 characters.Instead of querying all records to determine which record meets a given criteria, create a function field or function script that retrieves only the records that meet the criteria.
For a simple computation, it is better to use a function field or function script rather than store a computed value. The value is always calculated on retrieval. Another benefit of using function fields is that the database server performs the transformation rather than the application node.
Function fields versus calculated fields
The values of the calculated fields are stored in the database. The values of function fields or function scripts are not stored in the database, but are calculated at the time of retrieval. Function field values are always up to date.
Function fields versus business rules
Use function fields or scripts when business logic is based on a simple transformation of one or more existing fields. Function fields and scripts let you implement business logic without storing and maintaining the result of a transformation.
Function fields versus filters, query strings, and Rhino
Rather than calling Rhino to perform string transformations, you can use a function field or function script to perform the transformations for you. Function fields and function scripts are more efficient and result in up-to-date values that do not have to be stored or maintained.
Function field limitations
- Function fields cannot be directly audited or indexed.Note: To index a function field as if it were a regular field, make sure the individual fields used by the function are indexed. Or for best performance, make sure that there is a composite index including all fields that are used in the function.
- Function fields cannot be encrypted, since a function field value is never stored in the database.
- Function fields cannot be converted to regular fields or vice versa.
- Function fields that you create in the Reporting UI do not support dot-walking. For more information, see Configure function fields in Reporting.
- Security is evaluated on the components of the function and on the calculated value of the field. When used in visualizations, sections that contain information that the user is not permitted to see are hidden from the user.
- Field function names must be unique.
Defining platform functions
- Use the following application programming interfaces (APIs) to build and use functions
in a script.
Table 1. Function APIs APIs Description Scoped GlideDBFunctionBuilder Construct the function to perform a SQL operation. GlideRecord - addFunction(Object function) Apply the function to a GlideRecord. GlideDBFunctionCaseBuilder - Global Build case statements. - Create a field that holds the function definition, as shown in the following
example.
Select the Function field check box on the Dictionary Entry [sys_dictionary] form. This action specifies that the field runs a function rather than stores a value.
glidefunction operations
glidefunction:<operation>
syntax. When providing a field as an
argument, you can dot-walk to related fields. For example,
cmdb_ci.name
.Create a function field to perform database functions
Create a field that displays the results of a database function, such as a mathematical operation, field length computation, or day of the week calculation. Test in a subproduction instance before deploying to a production instance.
Before you begin
Procedure
Result
If the function definition is invalid, instead of the expected value you receive the message Invalid function if the function field is a string type field, or an empty value for other field types.