Mapping options
Summarize
Summary of Mapping options
This content explains various field mapping methods available in ServiceNow for importing data into production tables. It highlights how to handle different data transformation scenarios, including automatic mapping, manual mapping assistance, date format conversions, duration field mappings, scripting for source value calculations, and handling binary or BLOB data imports.
Show less
Mapping Methods
- Automatic Mapping Utility: Automatically matches import set fields to production table fields when names align. Users can confirm and adjust mappings using the mapping assist utility before transforming data.
- Mapping Assist Utility: Provides a visual interface to map source fields to one or multiple destination fields, enabling more flexible field mappings.
Date Format Mapping
ServiceNow supports transforming date formats between source and target fields by specifying the source date format. Common date format options include variations of day-month-year, month-day-year, and year-month-day with optional time and timezone elements. Custom formats can specify 24-hour time using HH:mm:ss. Proper date format mapping ensures accurate date imports.
Mapping Duration Fields
Duration fields in ServiceNow store values as milliseconds. To map duration data:
- Calculate duration from start and end dates using JavaScript in a transform map script.
- Convert existing duration values (e.g., seconds) into milliseconds via scripting.
Sample scripts demonstrate how to perform these conversions by applying gs.dateDiff() or multiplying by 1000 for seconds-to-milliseconds conversion.
Using Scripts to Calculate Source Values
Source scripts allow transformation logic when:
- Source values require reformatting before mapping.
- Values need to be looked up or computed from multiple fields.
- Creating compounded or calculated coalesce values.
Scripts assign the calculated value to the global variable answer. This enables flexible and dynamic data transformations during import.
Mapping Binary or BLOB Fields
Binary data imported from JDBC sources is converted into attachments stored in the sysattachment table. The import set only stores the attachmentâs sysid, not the binary data itself.
To associate these attachments with target records during transformation, use GlideRecord API scripts in onAfter transform events. This ensures attachment records link correctly to the target table rows after import.
Specific example scripts show how to:
- Reassign attachments to a target record by setting
tablenameandtablesysid. - Handle images imported directly to
dbimageby setting appropriate content types and filenames for display.
Practical Benefits for ServiceNow Customers
- These mapping options allow customers to efficiently import and transform data from varied sources with minimal manual effort.
- Accurate date and duration conversions ensure data integrity in time-related fields.
- Script-based transformations support complex business logic during data import, enabling tailored data integration.
- Handling binary attachments seamlessly integrates external files into ServiceNow records.
By leveraging these mapping capabilities, customers can streamline data imports, maintain data quality, and customize transformations to fit their unique data scenarios.
You can map fields in a number of ways depending on the circumstances of the import and whether data must be transformed prior to loading onto a production table.
It is also important to note that any given import operation may require taking advantage of multiple mapping methods, and these methods can be readily used in conjunction with one another.
Automatic Mapping Utility
The simplest mapping method is where all of the field names of the import sets match the names of the fields on the production tables onto which the data will be transformed. In this case, simply click Auto map matching fields in the related list in the Table Transform Map form and confirm proper matching. If there are any discrepancies in terms of how fields were automatically matched, use the mapping assist utility to correct them. When all fields are matched properly, click the Transform related link to begin transforming data onto the destination table.
Mapping Assist Utility
Changing the Date Format
| Date Format | Description |
|---|---|
| dd-MM-yyyy | Day-month-year |
| dd-MM-yyyy hh:mm:ss | Day-month-year hours-minutes-seconds |
| dd-MM-yyyy hh:mm:ss z | Day-month-year hours-minutes-seconds timezone |
| MM-dd-yyyy | Month-day-year |
| MM-dd-yyyy hh:mm:ss | Month-day-year hours-minutes-seconds |
| MM-dd-yyyy hh:mm:ss z | Month-day-year hours-minutes-seconds timezone |
| yyyy-dd-MM | Year-day-month |
| yyyy-MM-dd | Year-month-day |
| yyyy-MM-dd hh:mm:ss | Year-month-day hours-minutes-seconds |
To denote 24 hour time format, specify a custom date format using HH:mm:ss instead of hh:mm:ss.
Converting from a 24-hour to 12-hour date format might cause times from 12:00 to 23:59 to be formatted as 00:00 to 11:59.
Mapping to a Duration Field
- Calculate the duration from a start and end date
- Convert an existing duration value into a ServiceNow duration value
Calculating a Duration Value from a Start and End Date
- Navigate to .
- Select the transform map you want to calculate a duration value. For example, the Notification transform map that imports into the Incident table.
- Select the Run script check box.
- Enter JavaScript to transform the start and end dates into a duration. See the sample script.
- Click Update.
target.duration = gs.dateDiff(source.u_start.getDisplayValue(), source.u_end.getDisplayValue(), false);Convert a Duration Value into a ServiceNow Duration Value
- Navigate to .
- Select a transform map.
For example, the Notification transform map that imports into the Incident table.
- Select the Run script check box.
- Enter JavaScript to convert existing duration values into a ServiceNow duration values. See the sample script.
- Click Update.
//Transform the value in source.u_duration from seconds to milliseconds
target.duration.setDateNumericValue(source.u_duration * 1000);//Transform the value in source.u_duration to ServiceNow format
target.duration.setDateNumericValue(source.u_duration);Using a Script to Calculate a Source Value
- The source value is not in the format for the mapped target value.
- You want to look up a value before mapping to the target field.
- The source value must be computed from multiple fields.
- You need to create a compounded or calculated coalesce value in the target field.
A source script expects the calculated value to be set in the global variable
answer.
Mapping Binary or BLOB Fields
ServiceNow uses a special process to import binary and binary large object (BLOB) data from JDBC data sources. All binary data is automatically converted into a record in the Attachment [sys_attachment] table before the transformation occurs. The import set table only stores the attachment record's sys_id value in the import table field instead of the actual binary value. For example, suppose you use a JDBC data source to import data from a CA Service Desk system, which stores each record's key value as binary data. When you import the Service Desk key values into a ServiceNow table, the ServiceNow field only contains a sys_id reference to the corresponding binary data in the Attachment Record [sys_attachment] table rather than the actual binary data.
onAfter script. The script needs to run in an onAfter event
because the target.sys_id object is only available after the data is placed in
the import set table. For example, to map the resulting attachment to the target transform
record, you can use the following
script.var agr = new GlideRecord("sys_attachment");
agr.addQuery("sys_id", source.u_blob_field);
// the source field needs to be mapped to the source that is the BLOB
agr.query();
if(agr.next()) {
agr.table_name = "cmdb_ci"; // the target table of the transform map
agr.table_sys_id = target.sys_id; // the target record
agr.content_type = source.u_contentype;
// the content type string if available,
// this becomes the mime encoding when clicking an attachment link
agr.update(); // finally, move/re-attach the attachment to the target row }db_image table, run the following
onAfter script to display the
image:var strTemp = source.u_file_name;
var fType = strTemp.substr(- 3);
var iCont = "" ;
if(fType == 'jpg') {
iCont = 'jpeg' ; }
else {
iCont = fType; }
var agr = new GlideRecord("sys_attachment");
agr.addQuery("sys_id", source.u_blob_field);
agr.query();
if(agr.next()) {
agr.table_name = "ZZ_YYdb_image";
agr.table_sys_id = target.sys_id;
agr.content_type = 'image/' + iCont;
agr.file_name = 'image';
agr.update(); }