Skip to content
IT Canvass
Development · Lesson

Import & transform scripts

Quick answer

When you load data with import sets and transform maps, transform scripts are the code hooks that let you clean, enrich and control each row as it is written to the target table. They turn a dumb column-to-column map into a smart, defensible data pipeline.

Key takeaways

  • The transform events
  • An onBefore script
  • Coalesce and field maps
  • Try it Yourself

When you load data with import sets and transform maps, transform scripts are the code hooks that let you clean, enrich and control each row as it is written to the target table. They turn a dumb column-to-column map into a smart, defensible data pipeline.

The transform events

onStart
Once, before any rows, set up counters or lookups.
onBefore
Per row, before insert/update, clean or default fields.
onAfter
Per row, after the write, create related records.
onComplete
Once, at the end, log a summary.
onForeignInsert
When a referenced record must be created.

An onBefore script

// Normalise email and skip blank rows (function transformRow(source, target, map, log, isUpdate) { if (source.u_email.nil()) { ignore = true; // skip this row return; } target.email = source.u_email.toString().toLowerCase(); })(source, target, map, log, action==="update");
source, target and the ignore flag. source is the import-set row, target is the record being written. Set ignore = true in onBefore to skip a row, and use error = true with a log message to reject bad data instead of silently corrupting the target table.

Coalesce and field maps

A coalesce field decides insert-vs-update (match found = update). Prefer field maps and coalesce for the simple stuff; reserve scripts for transformations the mapping UI can't express.

Want to learn this properly?

Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.

Check your understanding

  1. To skip a row during transform you set...

    • A. ignore = true
    • B. current.update()
    • C. abort = 1
    Show answer

    A. ignore = true

    Setting ignore = true in onBefore skips writing that row.

  2. Which event runs once before any rows?

    • A. onStart
    • B. onAfter
    • C. onComplete
    Show answer

    A. onStart

    onStart runs a single time before processing rows.

  3. What decides insert vs update?

    • A. The coalesce field
    • B. The primary key only
    • C. Row order
    Show answer

    A. The coalesce field

    A coalesce match updates; no match inserts.

Frequently asked questions

What does the term Import & transform scripts refer to in ServiceNow?

When you load data with import sets and transform maps, transform scripts are the code hooks that let you clean, enrich and control each row as it is written to the target table. They turn a dumb column-to-column map into a smart, defensible data pipeline.

What is worth remembering about Import & transform scripts in practice?

A coalesce field decides insert-vs-update (match found = update).
CallWhatsAppEnquire