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

Fix scripts

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

Quick answer

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.

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.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
A fix script is captured in...

Frequently asked questions

What does the term Fix scripts refer to in ServiceNow?
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.
What is another point to note about Fix scripts?
Fix scripts record whether they have already run, so promotion won't double-apply them.
What else is worth knowing about Fix scripts?
Mark them clearly and remove or disable after they've served their purpose.
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