IMPORT SETS Jagan
IMPORT SETS Jagan
IMPORT SETS Jagan
that data
into ServiceNow tables.
Import Set table(Staging Table) -A table that acts as a staging location for records imported from a data
source before transforming those records. Fields on these tables are generated automatically based on imported data
and should not be modified manually.
Data source-A record that defines where to get the data to import. A data source may point to a file, a JDBC-compatible
database, or an LDAP organizational unit.
Transformation--The conversion of data from an import set table to another table according to the rules defined in a
transform map.
Transform map-A set of field maps that define the relationships between fields in an import set and fields on a table,
such as Incident.
During transformation, data is copied from the Import Set table to the destination table based on the transform map.
A single import set field may be mapped to multiple fields on other tables.
Foreign record insert A foreign record insert occurs when an import makes a change to a table that is not the target
table for that import.
This happens when updating a reference field on a table. For example, when updating a value for the caller on an
incident, the import is actually updating the sys_user table.
Coalesce-Lets you update existing target table records when transforming import data.
You can specify whether a Target field should be used to coalesce on when import set records are transformed. If the
field map Coalesce check box is selected, when the import set row is transformed, the instance checks for an existing
record in the target table that has the same value in the Target field as the import set row Source field.
If an existing record with a matching value in the target table is found, that record is updated. If no matching record is
found, then a new record is created in the target table.
JDBC JDBC imports require a valid transform map. Some network configurations may require a MID Server.
ServiceNow does not force import sets to provide values for all mandatory fields on a table. The Enforce mandatory
fields option on a Transform Map determines if mandatory fields are required to have values when importing data.
The Import Sets table acts as a staging area for records imported from a data source.
Note: You should not import data in extremely large chunks. Creating an extremely large import set can
cause delays and system outages.
A transform map determines the relationships between fields displaying in an Import Set table and
fields in an existing ServiceNow table, such as the Incidents or Users table.
Importing sets skip records when the data in the instance matches the data being imported.
Note: Import Sets run as user System and therefore cannot add data to encrypted fields.
Terminology
Key terms
Term Definition
Import Set table A table that acts as a staging location for records imported from a data source before transfor
those records. Fields on these tables are generated automatically based on imported data and
not be modified manually.
Data source A record that defines where to get the data to import. A data source may point to a file, a JDB
compatible database, or an LDAP organizational unit.
Transformation The conversion of data from an import set table to another table according to the rules defined
transform map.
Transform map A set of field maps that define the relationships between fields in an import set and fields on
such as Incident.
During transformation, data is copied from the Import Set table to the destination table based
transform map.
A single import set field may be mapped to multiple fields on other tables.
Coalesce Lets you update existing target table records when transforming import data.
You can specify whether a Target field should be used to coalesce on when
import set records are transformed. If the field map Coalesce check box is selected,
when the import set row is transformed, the instance checks for an existing record
in the target table that has the same value in the Target field as the import set row
Source field.
If an existing record with a matching value in the target table is found, that record is
updated. If no matching record is found, then a new record is created in the target table.
You can import data from several different file formats or external data sources.
File formats
Format Limitations
CSV CSV files must comply with the proposed CSV standard in RFC4180. In particular,
this means that double quotes may not appear inside fields. The first row of data in
an imported CSV file becomes the header row and defines the columns for that import set.
Excel Excel files must have the XLS or XLSX extension.
XML XML files must have a consistent XPath for each data row.
JSON For JSON arrays, the path for each row must specify the array root element twice, such
as /incidents/incidents.
JSON files should follow RFC-4627. For example, a single comma should separate a
value from the following name. Names within an object should be unique.
Predicates such as @element, [index], or text(), as well as Axis such as children,
siblings, or ancestors are not supported.
Custom (Parse by You can write custom Javascript to parse input lines into the list of maps.
Script)
ServiceNow can import data from the following external data sources.
Source table Import table containing the raw import set data. An import table is any table that extends the
Import Set Row [sys_import_set_row] table. You can select only tables within the
currently selected application scope.
Active Check box to make the transform map available for use.
Run business rules Check box to run business rules, workflows, approval engines, auditing, and field normalization
while the transformation inserts or updates data into the target table. Clearing this check box
runs GlideRecord.setWorkflow() with a value of false.
Enforce mandatory Selects whether to enforce mandatory fields on the target table:
fields o No: Do not enforce mandatory fields.
o Only Mapped Fields: Enforce mandatory mapped fields only.
o All Fields: Enforce all mandatory fields.
Copy empty fields Check box to copy empty field values and override existing target field values.
Create new record Check box to create a new record when all coalesce fields are empty, instead of ignoring the
on empty coalesce record or overwriting an existing record.
fields If Coalesce empty fields is selected for any field in the record, the record is coalesced.
Target table The table in which you want the transformed data to be inserted. You can select only tables
within the currently selected application scope or the global scope, or tables that grant write
access to other applications.
Order Order in which to apply transform maps if more than one map fits the conditions. The system
runs transform maps from lowest to highest Order.
Run script Check box to define a script that transforms field values in the source table to the target table.
Script Transform map script that transforms field values in the source table to the target table. The
system runs the transform map script in addition to any field maps.
To create a Transform Event Script, switch to the Transform Scripts related list in a Transform Map
and click the New button.
The When option in the Transform Script trigger specifies when in the transformation process the
script should run.
onStart: executes at the start of an import before any rows are read
onAfter: executes at the end of a row transformation and after the source row has been
transformed into the target row and saved
onBefore: executes at the start of a row transformation and before the row is transformed into
the target row
onChoiceCreate: executes at the start of a choice value creation before the new choice value is
created
onComplete: executes at the end of an import after all rows are read and transformed
onForeignInsert: executes at the start of the creation of a related, referenced record before the
record is created
onReject: executes during foreign record or choice creation if the foreign record or choice is
rejected. The entire transformation row is not saved.
Transformation script variables :
source : Contains the import source record currently being transformed. Specify a specific field from the
source record as an object property.
target : Contains the import target record currently being inserted. Specify a specific field from the target
record as an object property.
map : Contains the transformation map record currently being used for the transformation process. Specify
a specific field from the transform map record with one of these properties.
log : Log information about the current import process. Each log level has its own method.
action : Specify the transformation action occurring on the target record. This value can be either "insert" or
"update".
ignore : When set to true, skips or aborts the current import action. In onStart scripts, this variable aborts
the entire transformation process. In onBefore scripts, this variable only skips the current row being
transformed.
error : When set to true, aborts the current import action and logs an error message in the Import Set Log.
error_message :When an error occurs, adds the specified error message to SOAP response.
status_message : Adds the specified status message to SOAP response.
For example, when coalescing, the requirement might be to update only records that match and not
insert any new records. To meet the update records only requirement requires an onBefore Transform
Script. The onBefore script executes after ServiceNow has determined whether there is a matching
record in the target table and before the insert happens.
The action string variable is automatically created. It has two possible values: insert and update. The action
variable is set after coalescing determines if there is a match (update) or no match (insert).
The ignore boolean variable is automatically created. When true, the ignore variable stops the
transformation process for the source data row.
transform events and their contextual variables
onComplete When: The onComplete event script is processed at the end of an import run, after all data rows are read
and transformed.
onBefore When: The onBefore event script is processed at the start of a row transformation, before the source row
is transformed into the target row.
When: The onForeignInsert event script is processed at the start of the creation of a related,
referenced record, before the record is created.
onForeignIns
ert
Import Set JS objects available to be referenced and their context in
the onForeignInsert event
Import Type Context in the onForeignInsert
Set JS import set event
object
source GlideRecord The row of the source table that is
currently being processed.
target GlideRecord The row of the target table that is
currently being processed.
map GlideTransformMap Read-only information about the
current transform map record.
log Function The log object for the current import
run. For example, log.info(...),
log.warn(...), log.error(...).
action String Action returns a value of either
"insert" or "update" indicating
whether the current target row is
about to be created or updated.
name String Evaluates to the field name of the
target record for which a foreign
record that is about to be created.
value String Evaluates to the display value from
the source record for which a foreign
record is about to be created.
action String Action returns a value of either
"insert" or "update" indicating
whether the current target row is
about to be created or updated.
ignore Boolean When set to true, ignores the
creation of a new foreign or related
record.
error Boolean When set to true, rejects the entire
transformation row, no data is saved
for this row.
Example:
//Create an event.
e.insert();
onChoiceCreate When: The onChoiceCreate event script is processed at the start of a choice value creation,
before the new choice value is created.
onReject When: The onReject event script is processed during the occurrence of a foreign record or choice
creation, and the foreign record or choice is rejected ,the entire transformation row is not saved.
Example:
//Create an event
var e = new GlideEvent("myimport_onReject", action, "", "");
e.insert();
Transformation events occur during the process of transforming an import set table onto a table.
These events modify the transformation behavior from any type of mapping specification. Transformation
Event scripts modify the processing of the events at various stages of the transformation.
For example, the processing of a mapping operation defined using the Mapping Assist Utility can be
manipulated using the event scripts. There are a number of import set JavaScript objects that are accessible
during these events. These objects represent tables or portions of tables. It is important to note that what
these objects refer to varies depending on the context of the event in which they are referenced.
The following is a table of all of the transform events and their contextual variables:
Transformation script variables
Multiple variables can be used to define explicit mapping relationships in a transform map script.
Description: Contains the import source record currently being transformed. Specify a specific
Example:
var x = source.incident_state;
Description: Contains the import target record currently being inserted. Specify a specific field
Example:
target.incident_state = "active";
Description: Contains the transformation map record currently being used for the transformation
process. Specify a specific field from the transform map record with one of these properties.
name
sys_id
source_table
target_table
order
Example:
var x = map.order;
Type: Function
Description: Log information about the current import process. Each log level has its own
method.
Example:
Type: Function
Description: Specify the transformation action occurring on the target record. This value can be
Example:
if(action =="insert"){
ignore = true;
Description: When set to true, skips or aborts the current import action. In onStart scripts, this
variable aborts the entire transformation process. In onBefore scripts, this variable only skips the
Example:
if(source.u_user_name.nil()){
ignore = true;
Type: Boolean
Description: When set to true, aborts the current import action and logs an error message in the
Example:
if(source.name=="no_tranform"){
error = true;
Description: When an error occurs, adds the specified error message to SOAP response.
Example:
if(source.name=="no_tranform"){
error = true;
Example:
if(action =="insert"){
Script:
There are two types of Transform Map scripts:
Explicit Transform Map scripts, which explicitly define mapping relationships
Transformation Event scripts, which modify the processing of events at different stages of a transformation
Explicit
An explicit Transform Map script explicitly defines mapping relationships in the Transform Map record itself. It runs in
the context of "after" the source field values have been copied over to the target record, and before they are written to
the database.
Event Scripts
The onStart event script is processed at the start of an import run, before any data rows are read.
The onComplete event script is processed at the end of an import run, after all data rows are read and
transformed.
The onBefore event script is processed at the start of a row transformation, before the source row is
transformed into the target row.
The onAfter event script is processed at the end of a row transformation, after the source row has been
transformed into the target row and saved.
The onForeignInsert event script is processed at the start of the creation of a related, referenced record,
before the record is created.
The onChoiceCreate event script is processed at the start of a choice value creation, before the new choice
value is created.
The onReject event script is processed during the occurrence of a foreign record or choice creation, and the
foreign record or choice is rejected, the entire transformation row is not saved.
JSON vs XML
Both JSON and XML can be used to receive data from a web server.
The following JSON and XML examples both define an employee’s object, with an array of 3
employees:
JSON Example
{"employees":[
{ "firstName":"John", "lastName":"Doe" },
{ "firstName":"Anna", "lastName":"Smith" },
{ "firstName":"Peter", "lastName":"Jones" }
]}
XML Example
<employees>
<employee>
<firstName>John</firstName> <lastName>Doe</lastName>
</employee>
<employee>
<firstName>Anna</firstName> <lastName>Smith</lastName>
</employee>
<employee>
<firstName>Peter</firstName> <lastName>Jones</lastName>
</employee>
</employees>
XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript
function.
Using XML
Using JSON