Importing Data
Guide for importing external data into ServiceNow using the Fluent API. Covers Data Sources, staging tables, Import Sets (transform maps), and the three-component pattern required for every data import.
When to Use
- Importing external data from CSV, Excel, JSON, XML, JDBC, LDAP, or REST sources
- Setting up staging tables and transform maps for data integration
- Building applications that ingest data from external systems
- Configuring field mappings, coalesce rules, and transform scripts
Instructions
Three-Component Pattern
Every data import requires three separate components created in order:
- Staging Table (Table API): extends
sys_import_set_row, defines all columns for imported data. Must be created FIRST. - Data Source (Record API on
sys_data_source): references the staging table by name inimport_set_table_name. Defines how to connect and load data. Must be created SECOND. - Import Set (ImportSet API): references the staging table by name in
sourceTable. Defines how to map data from staging to target. Must be created THIRD.
All three components MUST use the exact same staging table name.
Collecting Mandatory Fields
Before generating data source code, collect format-specific mandatory fields:
- XML format: requires
xpath_root_node(e.g.,//product,/root/items/item) - JSON format: requires
jpath_root_node(e.g.,$.employees[*],$.data.records) - JDBC format: requires either
table_nameorsql_statement - LDAP format: requires complete LDAP chain (server config, OU config, data source)
- REST format: requires
request_actionreferencing an Integration Hub action - CSV/Excel: no format-specific mandatory fields
Password Handling
Pre-populate all configuration fields (hostnames, ports, usernames, database names) with provided values. Leave password fields empty ('') with a // LEAVE EMPTY comment -- passwords are set manually in ServiceNow after deployment.
Transform Map Configuration
- Set coalesce fields on at least one field to prevent duplicate records during import
- Use simple string mappings (
target_field: 'source_field') for direct field copies - Use object mappings for coalesce, date format, reference fields, or source scripts
- For complex transformation logic (>10-15 lines), extract to TypeScript functions in server modules
Key Concepts
- Data source types: File (CSV, Excel, JSON, XML), JDBC (database), LDAP, REST (Integration Hub), Custom (Parse by Script)
- File retrieval methods: Attachment (direct upload), FTP, SCP, SFTP, HTTP, HTTPS
- Import flow: External Source -> Data Source -> Staging Table -> Transform Map -> Target Table
- Coalesce: Field-level setting that enables record matching -- prevents duplicates by updating existing records instead of inserting new ones
- enforceMandatoryFields: Controls mandatory field validation during import:
no,onlyMappedFields,allFields - runBusinessRules: Disable for bulk imports (performance); enable selectively for business logic validation
LDAP Data Sources
LDAP imports require a chain of records: ldap_server_config -> ldap_ou_config (references server) -> optionally ldap_server_url (references server) -> sys_data_source (references OU via ldap_target). Use record object references (not hardcoded sys_id strings) for LDAP cross-table references.
Avoidance
- Do not create a data source without first searching for existing ones that may already match
- Do not generate XML/JSON data source code without
xpath_root_node/jpath_root_node-- the data source will deploy but fail to import data - Do not create an ImportSet without a corresponding Data Source and Staging Table -- all three components are required
- Do not use mismatched table names between Data Source (
import_set_table_name) and ImportSet (sourceTable) - Do not hardcode sys_id strings for LDAP references -- use record object references
- Do not include passwords in generated code -- leave empty for manual configuration
API Reference
For the full ImportSet property reference, see the importset-api topic. Data sources are created using the Record API on sys_data_source -- see the three-component pattern in the examples below.