Unpacking ServiceNow Field Types: Your Guide to Building Robust Forms
Ever stared at a ServiceNow form and wondered how all those different input fields come to life? From simple text boxes to complex dropdowns that magically filter based on your previous selections, each element plays a crucial role in collecting and presenting data. At the heart of this magic lies the concept of Field Types.
In ServiceNow, fields are the fundamental building blocks of every record and form. Understanding their various types and how to configure them isn’t just about technical know-how; it’s about crafting intuitive, efficient, and robust applications that truly serve your users. Whether you’re a seasoned developer, an aspiring admin, or just someone looking to peek behind the curtain, mastering field types and their associated behaviors is non-negotiable.
This article will be your comprehensive guide, diving deep into the different field types ServiceNow offers, how to configure their behavior, and the various mechanisms available to control them – from dictionary entries to UI and Data Policies. We’ll explore practical examples, common pitfalls, and even touch upon what interviewers love to ask about these foundational concepts. So, grab a coffee, and let’s demystify ServiceNow fields!
The Foundational Ten: A Closer Look at ServiceNow Field Types
Think of field types as the different types of containers you use to store specific kinds of information. ServiceNow offers a rich palette, each designed for a particular data format and purpose. While there are many more than ten, here are some of the most commonly encountered and fundamental ones you’ll work with:
1. Reference Field
This is arguably one of the most powerful and frequently used field types. A Reference field allows you to “point” to a record in another table. Instead of typing out a user’s name or an incident number, you simply select it from a lookup list.
- Practical Use: Assigning an Incident to a specific User (referencing the User table), linking a Problem to an Incident (referencing the Incident table).
- Behind the Scenes: While you see a user’s name or incident number, the field actually stores the
sys_id(a unique 32-character identifier) of the referenced record. This is crucial for data integrity and performance.
2. String Field
The ubiquitous String field is your go-to for storing text data. It’s highly versatile, allowing for single-line inputs like names, short descriptions, or codes.
- Practical Use: Short Description of an Incident, Name of a User, a product code.
- Variations: While generally single-line, you can configure its display size or maximum length. For longer texts, you might opt for a String (Multi-line) or HTML field.
3. List Field
A List field is a variation of the Reference type but allows you to select and store multiple references to records from another table.
- Practical Use: Adding multiple affected CIs (Configuration Items) to an Incident, or listing multiple Watch List members for a task.
- Behind the Scenes: It stores a comma-separated list of
sys_ids of the referenced records.
4. Choice Field
Choice fields provide users with a predefined set of options to choose from, usually presented as a dropdown menu. This is excellent for standardizing data entry and ensuring consistency.
- Practical Use: Incident Priority (Critical, High, Moderate, Low), Status of a Change Request (New, Assess, Implement, Review, Close).
- Configuration: Choices are defined directly within the dictionary entry or via the Choices related list.
5. Email Field
Specifically designed to store email addresses, this field type often includes built-in validation to ensure the entered text is in a valid email format.
- Practical Use: User’s business email address, a contact email for an external vendor.
- Behavior: Often provides a mail-to link when displayed, making it easy to compose an email to the address.
6. Date/Time Field
As the name suggests, this field allows for the selection of both a specific date and time. It typically comes with a calendar picker and a time selector for user convenience.
- Practical Use: Incident Created Date/Time, Scheduled Start/End times for a Change Request.
- Format: Stores date and time in a standardized format, usually UTC, for global consistency.
7. Date Field
Similar to Date/Time, but only allows the selection of a date, without a time component. Useful when the exact time isn’t relevant.
- Practical Use: Birthdate, Due Date for a task (where the specific time isn’t critical).
8. Boolean Field
A simple yet powerful field type that holds one of two possible values: true or false. It’s usually displayed as a checkbox on forms.
- Practical Use: Active status of a user, “Resolved” checkbox for an Incident, “VIP” status for a customer.
- Values: Stores
trueorfalsein the database.
9. Integer Field
Used for storing whole numbers (integers). ServiceNow often includes basic validation to ensure only numeric input.
- Practical Use: Number of days, a count of items, an age.
- Precision: Can be configured with a maximum length to control the range of numbers.
10. Journal Field
Journal fields are designed for tracking ongoing commentary or updates, appending new entries rather than overwriting existing text. They are crucial for audit trails and collaborative communication.
- Practical Use: Work notes, Activity log, Additional comments.
- Key Feature: Each entry is timestamped and associated with the user who made the entry, creating a chronological record.
11. Attachment Field (Implicit)
While not a discrete field type you select from a dropdown during field creation, the Attachment mechanism is intrinsically linked to records. It allows users to upload files (documents, screenshots, etc.) and associate them with a specific record.
- Practical Use: Attaching a screenshot to an Incident, a user manual to a KB article, or a signed document to a HR case.
- Control: You can enable/disable attachments for an entire table using attributes on the Collection field (more on this later).
Beyond Basic Types: Special Field Behaviors and Configurations
Knowing the types is just the beginning. ServiceNow empowers you to define sophisticated behaviors for these fields, making your applications dynamic and user-friendly.
Automatic Number Generation: The Number Field
You know those unique incident numbers (INC0010001) or change request numbers (CHG0005001)? That’s an auto-number field in action.
To create a field like the Incident number, you define a String field in the dictionary entry and configure its auto-numbering properties. You’ll typically find these settings under the “Control” tab of the dictionary entry:
- Prefix: The static part (e.g., “INC”, “CHG”).
- Number of Digits: How many digits follow the prefix (e.g., 7 for INC0010001).
- Auto-number: A checkbox you select to enable this functionality.
Why it’s important: Auto-numbering ensures unique identifiers for records, crucial for tracking, reporting, and preventing data collisions. It provides a standardized and easily recognizable reference for users.
Deep Dive into Reference Fields: Qualifiers and Values
We briefly touched upon Reference fields, but their true power comes with how you control what data users can select.
Setting Field Values Programmatically (current.setValue vs. current.setDisplayValue)
When you’re writing server-side scripts (like Business Rules or Script Includes), you’ll often need to set the value of a field. For Reference fields, there’s a subtle but important distinction:
-
current.setValue('field_name', value);This method requires you to provide the
sys_idof the referenced record for Reference type fields. If you provide a display value, it will likely fail or store incorrect data. It directly sets the underlying database value.Example:
current.setValue('assigned_to', 'c2509121c0a80164000302008f36c56c');(where the long string is the sys_id of a user). -
current.setDisplayValue('field_name', value);This method is more user-friendly as it allows you to provide the display value (e.g., the user’s name) of the referenced record. ServiceNow will then automatically look up the corresponding
sys_idand store it. This is particularly useful when you’re working with data from external sources that only provide display names.Example:
current.setDisplayValue('assigned_to', 'Fred Luddy');
Interview Relevance: This is a classic interview question! Knowing the difference demonstrates a deep understanding of how ServiceNow handles reference data.
Reference Qualifiers: Restricting Your Choices
Imagine a reference field for “Assigned To” that shows every single user in the system – active or inactive, IT or HR. That would be chaotic! Reference Qualifiers are your best friend here. They are used to restrict the data shown in Reference and List type fields, ensuring users only see relevant options.
There are three main types:
1. Simple Reference Qualifier
This is the most straightforward method. You specify a fixed query directly in the dictionary entry. It’s static and doesn’t change based on other field values.
- Description: Define a static filter condition.
- Example: You want the “Assigned To” field to only show active users. In the reference field’s dictionary entry, you set the reference qualifier condition:
active=true. Or perhaps only IT users:department.name=IT^active=true. - How to Use: Navigate to the dictionary entry of your reference field, locate the “Reference qualifier” section, and enter your conditions.
2. Dynamic Reference Qualifier
Dynamic qualifiers provide a more adaptable approach. They use a pre-defined “Dynamic Filter Option” that can generate a query based on the current context or complex logic.
- Description: Leverages a reusable Dynamic Filter Option to create context-aware queries.
- Example: Displaying only Incidents assigned to the same assignment group as the *current user*. You’d create a Dynamic Filter Option that builds a query like
assignment_group=javascript:gs.getUser().getMyGroups(). - How to Use:
- Create a Dynamic Filter Option (System Definition > Dynamic Filter Options). Define the logic there.
- In the reference field’s dictionary entry, select “Dynamic” for the reference qualifier and choose your created dynamic filter option.
3. Advanced Reference Qualifier (JavaScript Reference Qualifier)
When your filtering needs are highly complex, dependent on multiple fields, or require intricate logic, the Advanced (JavaScript) Reference Qualifier is your solution. You write a custom JavaScript snippet that returns the query string.
- Description: Uses custom JavaScript to construct a dynamic and complex query string.
- Example: Filtering the Incident table to show only incidents assigned to the current user’s assignment group AND with a priority less than 3.
javascript: 'assignment_group=' + gs.getUser().getRecord().getValue('assignment_group') + '^priority<3';This script fetches the current user's assignment group sys_id and combines it with the priority condition.
- How to Use: In the reference field's dictionary entry, select "Advanced" for the reference qualifier type and enter your JavaScript code. Remember, the script must return a valid encoded query string.
Differences Between Qualifier Types:
- Simple vs. Dynamic: Simple is static and fixed. Dynamic is pre-configured to react to context, often using reusable logic defined in a Dynamic Filter Option.
- Dynamic vs. Advanced: Dynamic leverages predefined options (less coding for similar scenarios, more reusable). Advanced gives you full programmatic control with JavaScript for truly unique and complex scenarios.
- Simple vs. Advanced: Simple is for fixed conditions. Advanced is for highly dynamic conditions generated by custom code. Simple is easy to implement; Advanced requires scripting knowledge.
Interview Relevance: Expect questions on all three, especially their differences and when to use each. Demonstrate you understand the trade-offs between simplicity, reusability, and power.
Dependent Values: Cascading Choices
Ever picked a "Category" and then seen the "Subcategory" field instantly filter its options? That's Dependent Values in action! This feature is critical for creating intuitive forms and ensuring data consistency.
Dependent values filter the available choices in one field (the dependent field) based on the selection made in another field (the parent field). This is extremely common for cascading dropdowns.
Steps to Configure Dependent Values:
- Identify Parent and Dependent Fields: For instance, Category (parent) and Subcategory (dependent). Both must typically be Choice fields, though the parent can sometimes be a Reference.
- Configure the Parent Field: Ensure your parent field (e.g., Category) has its list of possible values defined.
- Configure the Dependent Field:
- Go to the dictionary entry of the dependent field (e.g., Subcategory).
- Locate the "Dependent field" attribute and select your parent field (e.g., Category).
- Now, when you define the choices for the dependent field (Subcategory), you'll have an additional column to link each subcategory choice to a specific parent category value.
Example:
- Parent Field: Category (values: Hardware, Software, Network)
- Dependent Field: Subcategory (dependent on Category)
You'd define choices for Subcategory like this:
| Label | Value | Dependent Value (Parent Value) |
|---|---|---|
| Laptop | laptop | Hardware |
| Desktop | desktop | Hardware |
| Operating System | os | Software |
| Application | app | Software |
| Router | router | Network |
This configuration ensures that when a user selects "Hardware" for Category, only "Laptop" and "Desktop" appear in Subcategory.
Calculated Values
Sometimes, a field's value isn't directly input by a user but is derived from other fields on the same record. That's where calculated values come in.
If you want to calculate a field value based on other field values using the current object (server-side), you use a Calculated Dictionary Property.
- How to Use: In the dictionary entry of the field you want to calculate, check the "Calculated" checkbox. A new field, "Calculation," will appear where you can enter a JavaScript expression that returns the desired value.
- Example: A "Total Cost" field could be calculated as
current.quantity * current.unit_price. Or a "Due Date" field that automatically adds 5 days to the "Created" date:(function calculateDue(){ var gdt = new GlideDateTime(current.sys_created_on); gdt.addDays(5); return gdt; })(); - Caveats: While powerful, calculated fields can impact performance, especially if the calculation is complex or involves many records. Use them judiciously.
Display Field: The Record's Public Face
Every table can, and should, have one designated "Display Field." This field represents the primary human-readable identifier for a record when it's referenced elsewhere in the system.
- What it is: A field in a table whose value is used to display a record in reference fields, lists, and other lookups. For example, for a user record, "Name" (first_name + last_name) is often the display field. For an incident, it's the "Number" field.
- Why only one? ServiceNow prohibits setting two fields as "Display" on one table because it would lead to confusion. If the system had two primary identifiers, it wouldn't know which one to show when referencing that record from another table. Consistency is key.
Controlling Field Behavior: Beyond Just Data
Fields don't just hold data; they interact with users. You often need to control whether a field is visible, mandatory, or read-only based on certain conditions. ServiceNow provides several powerful mechanisms for this, each with its own scope and order of precedence.
Ways to Make a Field Mandatory, Read-Only, or Visible
You have a toolbox full of options to manage field behavior:
- From Dictionary Properties: The most fundamental level, affecting the field globally.
- Dictionary Overrides: For child tables, allowing deviation from the parent's dictionary definition.
- UI Policies: Client-side logic for dynamic form behavior.
- Data Policies: Both client and server-side enforcement for data integrity.
- g_form.setMandatory(Script) / g_form.setReadOnly(Script): Client-side scripting for highly customized scenarios.
Dictionary Properties and Attributes
The dictionary entry of a field is where its core properties and behavior are defined.
- Attributes: These are special properties you can add to a field's dictionary entry (or even a table's "Collection" entry) to modify its behavior. They're key-value pairs that influence how the field renders or functions.
- Examples of Attributes:
no_email: Prevents the field's value from being included in email notifications.no_attachment: Disables the ability to add attachments to a record (when applied to the Collection field).no_add_me: For List fields, prevents the "Add Me" button from appearing.tree_picker: For Reference fields, displays a hierarchical picker instead of the standard lookup.
How to Enable/Disable Attachments on the Form Using Attributes
This is a common requirement. To control attachments for an entire table (e.g., Incident), you don't add the attribute to a specific field. Instead, you add it to the Collection field of that table.
In the dictionary entry for the "Collection" type for your table (e.g., "Incident [incident]"), you would add the attribute no_attachment=true. This will disable the attachment icon/functionality for all records in that table. Removing or setting it to false (not explicitly necessary as false is default) would re-enable attachments.
Dictionary Overrides
ServiceNow tables often extend other tables, inheriting their fields and properties. But what if a child table needs a specific field to behave differently from its parent? That's where Dictionary Overrides shine.
- Purpose: They allow a field in a child table to have a different value or behavior than the same field in a parent table.
- Example: The "Priority" field might default to "4 - Low" in the general "Task" table (the parent). However, in the "Incident" table (which extends Task), you might want the default "Priority" to be "3 - Moderate." A Dictionary Override on the Incident table for the Priority field would achieve this.
- Properties you can override: You can override many properties, including:
- Default value
- Mandatory status
- Read-only status
- Reference qualifier
- Display value
- Choice list options
Interview Relevance: A very common question. It demonstrates understanding of table inheritance and customization.
UI Policies (Client-side)
UI Policies are client-side logic used to dynamically control form behavior based on conditions. They operate in the user's browser, making changes immediately visible without a server round trip.
- Purpose: Make fields mandatory, read-only, visible, or hide/show related lists at certain conditions.
- Key Checkboxes:
- Global: When checked, the UI Policy applies to all form views. If unchecked, you can specify a particular "View" for the policy to apply to.
- Reverse if false: If selected, the actions applied by the UI Policy (e.g., making a field mandatory) will be reversed when the condition evaluates to false. If unchecked, the actions only apply when true, and no action is taken if false.
- On Load: If selected, the UI Policy conditions and actions are evaluated and applied immediately when the form loads. If unchecked, the policy only triggers when a field related to its conditions changes.
- Inherit: When checked, the UI Policy will also apply to child tables that extend the table on which the policy is defined.
- Can you write script in UI Policy? Yes! If you need more complex logic than the standard conditions or actions, you can enable the "Run scripts" checkbox. This allows you to write client-side JavaScript (in "Execute if true" and "Execute if false" script fields) that executes when the UI Policy condition is met or not met.
Example: If "Category" is "Hardware," make "Asset Tag" mandatory and visible.
Troubleshooting UI Policies:
- Not firing: Check 'On Load' if it should apply immediately. Ensure conditions are met. Verify 'Global' checkbox and 'View' if specific views are used.
- Conflicting policies: Multiple UI Policies targeting the same field can lead to unexpected behavior. Check their order and conditions.
- 'Reverse if false' confusion: If a field isn't reverting, ensure 'Reverse if false' is checked and no other policy is overriding it.
Data Policies (Client & Server-side)
Data Policies are the big brother to UI Policies. They enforce data integrity rules at both the client-side (forms) and server-side (all data sources, including imports, web services, and scripts).
- Purpose: Make fields mandatory, read-only, or visible at certain conditions, ensuring consistency regardless of how data enters the system.
- Key Difference from UI Policy: Data Policies enforce rules even if a user bypasses the UI (e.g., through an import set or API call). UI Policies only affect the form experience.
- Conversion from UI Policy: Yes, you can convert a UI Policy into a Data Policy. Open the UI Policy and look for a UI Action labeled "Convert this as Data Policy." This is useful for quickly promoting client-side rules to server-side enforcement.
- When UI Policy cannot be converted as Data Policy: A UI Policy cannot be converted if it involves client-specific UI elements or client-side scripting logic that has no server-side equivalent. Specifically:
- When you are controlling data visibility (UI Policy can hide, Data Policy can't hide data itself, only make it non-editable).
- When you are controlling the views.
- When you are controlling related lists (related lists are a UI concept).
- When you are controlling scripts (client-side scripts don't have direct server-side equivalents in data policies).
Example: Ensure "Assignment Group" is always mandatory if "State" is "In Progress," even if the record is updated via an import.
Troubleshooting Data Policies:
- Not applying: Data policies have an 'Order' field. Lower numbers run first. Check for conflicting policies with higher order numbers.
- Unexpected behavior: Ensure the 'Applies to all views' and 'Applies on import sets' checkboxes are set correctly for your use case.
Setting Default Values on a Field
Populating fields with sensible default values can significantly improve user experience and data entry efficiency.
Whenever the form is open, if you want to populate some default values on the form, you can set default values for that particular field.
- How to Set:
- Dictionary Entry: The most common way is directly in the field's dictionary entry, using the "Default value" field. This can be a static value or a simple JavaScript expression (e.g.,
javascript:gs.getUserID()for an assigned user, orjavascript:gs.beginningOfToday()for a date). - Dictionary Overrides: To set a different default value for a child table.
- UI Policy: For dynamic client-side defaults based on conditions.
- Client Script: For more complex client-side logic using
g_form.setValue(). - Business Rule: For server-side default setting (often `before insert` rules), especially when defaults depend on backend logic or other record values not yet available on the form.
- Dictionary Entry: The most common way is directly in the field's dictionary entry, using the "Default value" field. This can be a static value or a simple JavaScript expression (e.g.,
The "Collection" Field: The Table Itself
When you create a new table in ServiceNow, a special dictionary entry is automatically generated for it, with the type "Collection."
- What it represents: Dictionary entries with the "Collection" type represent the table itself, rather than a field on the table.
- Purpose: Changes such as attributes (like
no_attachment) or the "Read only" checkbox applied to this entry are applied to the entire table, rather than a specific field. - Automatic Creation: This entry is automatically created when a table is created and is fundamental for configuring table-level properties.
Troubleshooting Common Field-Related Issues
Even with a solid understanding, you'll inevitably run into situations where fields don't behave as expected. Here are some common troubleshooting tips:
- Field not visible/editable:
- Check ACLs (Access Control Lists) on the field and table. These are server-side security rules.
- Review UI Policies and Data Policies that might be making it hidden, read-only, or mandatory under certain conditions.
- Check Dictionary properties (e.g., 'Read Only' checkbox).
- Look for client scripts that might be manipulating visibility or editability.
- Incorrect value:
- Check default values in the dictionary.
- Are there any Business Rules (especially 'before' rules) or Client Scripts setting the value?
- For Reference fields, ensure the
sys_idis correct if set via script.
- Reference field not filtering correctly:
- Inspect the Reference Qualifier carefully. Test the query string directly in a list view.
- If it's a Dynamic or Advanced qualifier, debug the JavaScript to ensure it's returning the expected query.
- Check for conflicting dictionary overrides on child tables.
- Performance issues with fields:
- Complex Advanced Reference Qualifiers can slow down forms. Optimize your JavaScript.
- Extensive use of Calculated fields can impact database performance. Re-evaluate if the calculation can happen at report-time or asynchronously.
- Caching issues: Sometimes, changes to dictionary entries, UI Policies, or client scripts might not immediately reflect due to browser or instance caching. Try clearing your browser cache or performing a cache flush in ServiceNow (
cache.do).
Interview Relevance: What to Expect
Field types and their configuration are fundamental to ServiceNow. Expect interviewers to test your understanding thoroughly. Here’s what they often focus on:
- Defining field types: Be able to list and briefly explain common types like Reference, String, Choice, List, Date/Time, Boolean.
- Reference Qualifiers: A critical topic. Understand the three types (Simple, Dynamic, Advanced), their differences, and when to use each. Be ready to give examples or even write a basic JavaScript qualifier.
current.setValue()vs.current.setDisplayValue(): Crucial for demonstrating scripting knowledge with reference fields.- UI Policies vs. Data Policies: This is a must-know. Explain their scope (client/server), purpose, and when to use one over the other. Highlight the limitations of converting a UI Policy to a Data Policy.
- Dictionary Overrides: Explain their purpose in the context of table extension and inherited fields.
- Auto-numbering: How to set it up and why it's used.
- Dependent Fields: How to configure cascading choices.
- The "Collection" field: What it is and how it's used (e.g., for `no_attachment`).
- Making fields mandatory/read-only: Be able to list the different methods and briefly discuss their order of precedence (though a deep dive into precedence is often more advanced).
The key is not just to memorize definitions, but to explain the "why" and "when" for each concept, backed by practical examples.
Conclusion: Your Canvas for Data Management
ServiceNow field types are much more than just containers for data. They are the versatile tools that allow you to sculpt user interfaces, enforce data integrity, automate processes, and ultimately, build powerful applications that streamline operations. From the simplicity of a Boolean checkbox to the complexity of an Advanced Reference Qualifier, each field type and configuration option offers a unique way to refine your ServiceNow instance.
By understanding the nuances of each field type, their associated dictionary properties, and the powerful mechanisms like UI and Data Policies, you gain the ability to create truly robust, user-friendly, and maintainable solutions. So keep experimenting, keep building, and remember: every successful ServiceNow implementation starts with well-defined fields. Happy configuring!