A ServiceNow database view is a saved join. It links two or more tables so their fields can be read together in a report, list or script, with no manual joins. You build it under System Definition, give each table a short variable prefix, connect the tables in a Where clause, and check the output with the Try It link.
What a database view joins and why reporting teams use it
Take a typical question: how many incidents were resolved on the first call, grouped by category, and which metric sits behind each count? The incident table holds the incidents, the metric definition table names each measure, and the metric instance table records each measurement. A database view joins those tables into one pseudo-table. A view is a pseudo-table that combines data from each table in the view, so one report can read fields from all of them together.
Any user who can create a report can use a view as its source, so the same joins are not rebuilt each time. The platform does not treat a view as a custom table, so creating one carries no licensing impact.
Building the view: name, tables and the Where clause
Start at All > System Definition > Database Views with the admin role and select New. Name the view as you would name a table; capital letters become lower case and spaces become underscores. The label and plural control how the view appears in lists and forms.
Add tables from the View Tables related list. Each row has four settings.
| Setting | What it controls |
|---|---|
| Table | The table joined into the view |
| Variable prefix | The short name the Where clause uses for this table. Mandatory, and kept in lower case because uppercase can hide the view from lists. |
| Where clause | The join condition, written as prefix, underscore, field name. The entry mi_id points at the id field of the metric instance table. |
| Order | Left-to-right sequence, lowest value first. Space the values (100, 200, 300) so you can insert a table later. |
The Where clause supports the equals, not-equals, comparison, && and || operators. LIKE and CONTAINS are not supported, so link tables on sys_id with the equals operator. That keeps the full dataset in play for lists, glide queries and reports. The starting table has a blank Where clause. Later tables normally carry one, and the Left join flag only changes results for a table that has a Where clause.
Left joins: deciding which rows survive
Without a left join, a row needs a match in the joined table. Tick Left join and the left-hand table keeps its rows even when nothing matches on the right. The flag affects a view table’s results just when that table has a Where clause.
The standard example lists catalog tasks with their parents. Catalog Task is the starting table: prefix cat, order 100, no Where clause. Requested Item uses prefix item, order 200, the Where clause cat_parent=item_sys_id, and Left join ticked. Request uses prefix req, order 300, cat_parent=req_sys_id, and Left join ticked. User uses prefix user, order 400, cat_opened_by=user_sys_id, and Left join unticked.
A task whose parent is a requested item shows blank Request fields, and a task whose parent is a request shows blank Requested Item fields. Because both parent joins are left joins, a task still returns without a valid parent. The User join is not a left join, so a matching user must exist for the task to appear.
| Requested Item left join | Request left join | Rows returned |
|---|---|---|
| Ticked | Ticked | All catalog tasks, with blank parent fields where no parent exists |
| Unticked | Ticked | Catalog tasks that have a requested item as their parent |
| Ticked | Unticked | Catalog tasks that have a request as their parent |
| Unticked | Unticked | None, because no task can have both a requested item and a request as its parent |
Restricting fields and relabelling columns
By default a view returns all fields from each of its tables. To narrow the output, add View Field records in the View Fields related list. Once any field is listed, just the listed fields return. Keep one trap in mind: each join field named in the Where clause also needs its own View Field record. Without it, the field cannot return and the join fails. A Where clause that compares sys_id on the incident table therefore needs a sys_id record in that table’s list.
Two tables can share a field name, such as sys_updated_on, and both matter in one report. Relabel one through a Language File record under System Definition. Set the table to the view name, enter the label and plural, and set the element to the prefix and field name joined by an underscore, such as inc_name. The label alone changes; the field name stays the same.
Function fields: calculated columns with no stored data
A function field displays the result of a database function, such as a length count, a day-of-week calculation or a concatenation. The function is executed and its result appears in the view output. You can attach it to a physical table through the dictionary, or create it directly on the view.
On a view, the definition must use the view’s variable prefixes. Definitions start with glidefunction, then the operation, then its parameters, with constants in single quotes. With the incident table prefix inc2, the length of its description becomes glidefunction:length(inc2_description). With the metric instance prefix mi, a concatenation of the definition name and value takes the form glidefunction:concat(mi_definition.name,’ ‘,mi_value). Once saved, a function field cannot be turned back into a regular field, so check the definition first.
Testing gives a clear signal. The message Invalid function means the definition is invalid for a string field. An empty value means it is invalid for other field types. An unexpected value means you should review the definition itself.
Access checks, limits and performance
If ACLs exist on the view, they take precedence. When no view ACLs exist and glide.security.expander.view.legacy is false, underlying table ACLs apply. Existing field-level ACLs are also evaluated. The access control list explainer covers how rules are matched. For the wider setup, see the instance security and access control hub.
The property glide.security.expander.view.legacy defaults to false. When it is true, underlying table rules are ignored and read rules must be added to each view. On upgraded instances the property is not present by default, so add it as a system property set to true if that behaviour is wanted.
Cost grows with the number of tables and the number of records they hold, so put Where clauses on indexed fields. Other limits: a view cannot be created on a table in table rotation, its output cannot be edited, view tables cannot be data preservers in clone requests, and they are left out of FTP exports. For the wider picture on query cost, see the platform performance hub.
Scripts have a separate cap. The property glide.db.max_view_records defaults to 10,000 and limits the rows a GlideRecord query returns against a view inside a script. Lists and reports ignore it and read all rows. To change it, add the property to the System Property table and set its value. The GlideRecord explainer covers script queries in more depth.
Testing the view before anyone relies on it
Open the database view record and select the Try It related link. If you limited fields and results look wrong, confirm that each Where-clause field appears in View Fields. If the Try It link is missing, the tables the view needs are absent, which may mean a required plugin is not active.
After the test passes, the view appears under tables in the data sources for a visualization. The reporting and dashboards guide covers the report side.
Writing OR conditions without breaking the logic
The platform evaluates AND before OR. Consider closed incidents at priority 1 or priority 2. Written as (priority = 1 || priority = 2) && state = 6, the brackets group the two priorities, so the result is closed priority 1 and priority 2 incidents. Without brackets, as priority = 1 || priority = 2 && state = 6, the query reads as priority 1 or (priority 2 and closed). That returns all priority 1 incidents regardless of state, plus the closed priority 2 incidents.
Brackets around OR groups are the safe habit, in a view’s Where clause as well. Incidents related to a change request through either path can use inc_rfc = chg_sys_id || chg_parent = inc_sys_id. The encoded query explainer covers the same grouping in filters.
Views already shipped in the base system
The Database Views plugin and the Database Views for Service Management plugin ship ready-made views. The incident family includes incident_metric, incident_sla and incident_time_worked. The problem family includes problem_metric and problem_sla. The change family includes change_request_metric, change_request_sla, change_task_metric and change_task_sla. The catalog family includes sc_request_metric, sc_req_item_metric, sc_task_metric and sc_task_sla.
Metric views answer questions such as which changes closed by category, and SLA views answer which requests resolved within target. Check this list before building a join.
Frequently asked questions
Can a report on a database view change the underlying data?
No. The output of a database view cannot be edited, so a report on the view is read-only.
Why does my view return fewer rows after I change a left join?
Left joins affect a view table’s results just when that table has a Where clause. When a join is not ticked, the row needs a match in that table. In the catalog example, unticking both parent joins returns no rows, because no task can have both a requested item and a request as its parent.
Why does a script stop at 10,000 rows from my view?
The glide.db.max_view_records property defaults to 10,000 and caps GlideRecord queries against a view inside a script. Lists and reports read all rows. You can raise the cap by adding the property to the System Property table and setting its value.
Does a database view count as a custom table for licensing?
No. The platform does not treat a database view as a custom table, so creating one carries no licensing impact.