top of page

Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

Decoding ServiceNow Data Imports: Understanding the Sequence of Transform Scripts

Updated: Mar 26


Importing data into ServiceNow is a common task, and Transform Maps play a crucial role in ensuring that data lands in the correct tables and fields. For ServiceNow developers, understanding the order in which different Transform Scripts execute is essential for writing effective and efficient data transformation logic. This article will demystify the sequence of these scripts, providing clarity on how your data is processed during an import.


Introduction: Why the Order of Transform Scripts Matters in ServiceNow

When you import data into ServiceNow using an Import Set and a Transform Map, various scripts can be associated with the transformation process. These scripts allow you to manipulate the data at different stages, ensuring data quality and proper mapping to your target tables. Knowing the exact order of execution is vital for debugging issues, implementing complex transformations, and ensuring your data imports run smoothly and accurately.


Main Body: The Order of Execution for ServiceNow Transform Scripts

The execution of Transform Scripts follows a specific sequence, allowing you to hook into different points of the data transformation process.

Here's a breakdown of the order in which these scripts typically run:

1. onStart() Script:

This script executes only once at the very beginning of the data import process, before any data rows are read from the Import Set table. It's an ideal place to perform initialization tasks, set global variables, or log the start of the import.

Example Use Case: You might use onStart() to clear a temporary staging table or to initialize a counter for processed records.


2. For Each Record in the Import Set:

The following scripts execute for each individual record being processed from the Import Set table:

a) Coalesce Field Maps:

Before any other per-record scripts, the field maps configured for coalescing are evaluated. Coalescing determines if an incoming record should update an existing record in the target table or insert a new one based on matching field values.

Since coalescing logic executes before the onBefore() script, any changes made to coalesce fields within onBefore() will not affect the matching logic.


b) onBefore() Script:

This script executes at the beginning of the transformation for each row, before the source row is transformed into the target record. It allows you to inspect and modify the source data or even prevent the transformation of a specific record based on certain conditions.

Example Use Case: You could use onBefore() to validate the format of a date field or to skip processing records that do not meet specific criteria.


c) Source Script (within Field Maps):

For each field mapping in your Transform Map, you can define a Source Script. This script runs after the onBefore() script and allows you to manipulate the value being transferred from the source field to the target field.

Within a Source Script, you can use the current object to access the target record being populated. This allows you to modify the source field value based on other fields in the target record.

Example Use Case: You might use a Source Script to concatenate the values of two source fields or to perform a lookup to populate a reference field.


d) Transform Map Script (Run Script checkbox):

This script, often referred to as the "main" Transform Map script, executes after all the individual field mappings (including their Source Scripts) have been processed. It runs in the context of the target record just before it is written to the database.

Because the Transform Map Script runs before the onAfter() script, any values set in the Transform Map Script can still be modified or overridden in the onAfter() script if needed.

Example Use Case: You might use this script to set default values for fields that are not present in the import data or to perform more complex logic involving multiple target fields.


e) onAfter() Script:

This script executes at the end of the transformation for each row, after the target record has been transformed and saved to the database. It's useful for performing post-processing tasks on the newly created or updated record.

Example Use Case: You could use onAfter() to send a notification email when a new record is created or to trigger a workflow based on the imported data.


3. onComplete() Script:

This script executes only once at the very end of the data import process, after all data rows have been read and transformed. It's a good place to perform final cleanup tasks, generate summary reports, or send a completion notification.

Example Use Case: You might use onComplete() to update a status field on the Import Set record or to send an email summarizing the number of records imported.

Conditional Transform Scripts:

In addition to the main sequence, there are other Transform Scripts that execute under specific conditions:

  • onChoiceCreate(): This script runs when the transformation process encounters a choice value in the import data that does not exist in the target field's choices. It executes before the new choice value is created.

  • onForeignInsert(): This script runs when the transformation process needs to insert a record into a related, referenced table because the reference value in the import data does not match an existing record. It executes before the new related record is inserted.

  • onReject(): This script runs if the creation of a foreign record (during onForeignInsert) or a choice value (onChoiceCreate()) fails. When this script is triggered, the entire transformation for the current row is typically not saved.


Conclusion: Leveraging Transform Script Order for Effective Data Integration

Understanding the execution order of ServiceNow Transform Scripts is crucial for developers working with data imports. By strategically placing your custom logic within the appropriate script, you can effectively manipulate data, ensure data integrity, and automate post-import processes. Keep this sequence in mind when designing your Transform Maps to build robust and reliable data integration solutions in ServiceNow. Taking the time to understand this order will empower you to troubleshoot issues more efficiently and build more sophisticated data transformation workflows.

Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page