IT CanvassTalk to an advisor
Development · LessonReviewed by Sneha I, ServiceNow Trainer, 8 yrs · Updated · Published · current release · intermediate

ServiceNow Fix scripts

Run one-off, tracked data-remediation scripts that travel with your deployment.

Quick answer

A ServiceNow fix script is a server-side script that runs once to correct or migrate data and is captured in an update set, so it runs again when the work is promoted and records that it ran. Batch with setLimit, decide whether setWorkflow(false) should skip business rules, log the count, and disable it afterwards.

Key takeaways
  • Fix script vs background script
  • A safe fix script
  • Run tracking
  • Try it Yourself

A fix script is a server-side script designed to run once to correct or migrate data, and, crucially, to be captured in an update set so it runs automatically when your work is promoted to the next instance. It is the disciplined alternative to pasting code into background scripts in production.

Fix script vs background script

Fix script
Saved record, captured in update sets, re-runnable, auditable.
Background script
Ad-hoc, not tracked, not promoted, easy to forget.

A safe fix script

// Backfill blank category on old incidents var gr = new GlideRecord('incident'); gr.addQuery('category', ''); gr.setLimit(500); // batch to stay safe gr.query(); var n = 0; while (gr.next()) { gr.category = 'inquiry'; gr.setWorkflow(false); // skip business rules if intended gr.update(); n++; } gs.info('Updated ' + n + ' incidents');
Run in a sub-prod instance first. Fix scripts change data. Always test in dev/test, use setLimit to batch, and decide deliberately whether to call setWorkflow(false), skipping business rules can be right for a migration but wrong if downstream automation must fire.

Run tracking

Fix scripts record whether they have already run, so promotion won't double-apply them. Mark them clearly and remove or disable after they've served their purpose.

Try it YourselfJavaScript
▸ Press Run to execute.

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

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