Designing and Creating an Application · Topic 2 of 4
Designing the Data Model
CAD data model design: new tables vs extending Task, the table creation form, field types, reference fields, many to many relationships and Schema Map.
- 5 min
- Extending a table inherits all parent fields; the parent must be Extensible.
- Extend Task for work that is assigned and tracked through states.
- Scoped table names start with the scope namespace, such as x_acme_loans_.
What it is
The data model is the set of tables and fields your application stores its records in, and the relationships between them. Forms, lists, scripts, flows and access controls all attach to tables, so the data model is the first thing a developer builds after deciding the application is a good fit.
On the exam, data model questions ask whether to create a new table or extend one, which field type fits a requirement, and how to relate two tables.
How it works
New table or extended table
A new table can stand alone or extend an existing table. A child table inherits every field of its parent and can add its own. The parent must be marked Extensible before another table can extend it.
| Choice | When it fits | What you get |
|---|---|---|
| Extend Task | Work that is assigned, tracked through states and closed | Number, State, Assigned to, Assignment group, Short description, approvals and task features |
| Extend your own base table | Several record types in your app share many fields | Shared fields defined once, one list across all child types |
| Standalone table | Reference data such as a list of locations or product models | Only the fields you add, plus system fields |
Extending Task is the usual answer when a record represents work. Building those fields yourself on a standalone table wastes effort and loses features that already understand Task.
Creating a table
You create tables in Studio or App Engine Studio, or from System Definition > Tables, with your application selected. The table name automatically starts with the scope namespace, such as x_acme_loans_request.
The table form also offers useful options in one place:
- Extends table to choose a parent.
- Create module and Add module to menu to place a list module for the table in an application menu.
- Auto-number to give records a prefix and sequential number.
- On the Controls tab, Create access controls and a User role, so new ACLs are created for the table.
Every table gets system fields automatically, including sys_id, created and updated dates, and created by and updated by.
Choosing field types
| Need | Field type |
|---|---|
| Short free text | String |
| A value from a fixed list | Choice |
| A link to one record in another table | Reference |
| Links to several records in one table | List |
| Yes or no | True/False |
| A date and time | Date/Time |
| Notes that keep a history of entries | Journal |
Field definitions live in the dictionary. A dictionary override lets a child table change an inherited field, such as its default value or mandatory setting, without changing it on the parent.
Relating tables
A reference field stores the sys_id of one record in another table. Many requests can point at one user, so a reference field builds a one-to-many relationship. The referenced table's form can then show a related list of the records that point back at it.
A many to many relationship needs a third table that holds a reference to each side, created as a many to many definition. A List field stores several references in one field but is harder to report on and query than a proper relationship table.
Scripts follow references with dot-walking:
var gr = new GlideRecord('x_acme_loans_request');
gr.get(requestSysId);
gs.info(gr.requested_for.department.getDisplayValue());
Checking the design
Schema Map draws a table with its parents, children and the tables it references or that reference it. Use it to confirm the model before you build forms and scripts on it.
How the exam asks about this
- "Records are assigned to fulfillers, move through states and need approvals." Extend the Task table.
- "Each request must point at the user it is for." Add a Reference field to the User table.
- "Many assets can be in many kits, and each kit holds many assets." Create a many to many relationship table.
What to remember for the exam
- Extending a table inherits all parent fields; the parent must be Extensible.
- Extend Task for work that is assigned and tracked through states.
- Scoped table names start with the scope namespace, such as x_acme_loans_.
- The table form can create a module, auto-numbering and access controls with a user role.
- A reference field stores a sys_id and builds a one-to-many relationship.
- Many to many relationships need a third table with a reference to each side.
Adding a field to a parent table puts it on every child table. If only one child needs it, add it to that child, or use a dictionary override to change an inherited field there.
Common mistakes
Rebuilding Task fields on a standalone table. Number, State, assignment and approval fields already exist on Task. Extending Task gives them, and the features built on them, without extra work.
Using a Choice field for records. If the values have their own details, such as users or locations, they belong in a table and the field should be a Reference.
Using a List field where a relationship table is needed. A List field is quick but limited. When both sides have many links and you need reporting, build a many to many relationship.
Check yourself
When should a new application table extend Task?
When its records represent work that is assigned, tracked through states and closed, so it inherits fields such as Number, State and Assigned to.
What does a reference field store, and what relationship does it build?
It stores the sys_id of a record in another table and builds a one-to-many relationship.
How do you model a many to many relationship between two tables?
Create a third table that holds a reference to each side, defined as a many to many relationship.
Topic 2 of 4 in Designing and Creating an Application
Test yourself on Designing and Creating an Application
The full ServiceNow CAD question bank has 600 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by ServiceNow. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.