IT CanvassTalk to an advisor
Development · LessonBy , ServiceNow Trainer, 8 yrs · Published · current release · intermediate

Import & transform scripts

Shape and clean incoming data as it flows from an import set into target tables.

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.

Try it YourselfJavaScript
▸ Press Run to execute.

Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
To skip a row during transform you set...

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).
Practise this on your own free instance.
Set up your free instance →
Already working on ServiceNow and stuck on a live ticket?Get an expert ServiceNow developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support