Skip to content
IT Canvass
Development · Lesson

Fix scripts

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.

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. A fix script is captured in...

    • A. Update sets, so it promotes with your work
    • B. Nothing
    • C. A separate database
    Show answer

    A. Update sets, so it promotes with your work

    Fix scripts travel in update sets and run on promotion.

  2. Compared to a background script, a fix script is...

    • A. Tracked and re-runnable
    • B. Faster to type only
    • C. Never saved
    Show answer

    A. Tracked and re-runnable

    Fix scripts are saved, auditable and re-runnable.

  3. Before running a fix script you should...

    • A. Test in a sub-prod instance and batch it
    • B. Run straight in prod
    • C. Delete the table
    Show answer

    A. Test in a sub-prod instance and batch it

    Test first and use setLimit to batch changes.

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.
CallWhatsAppEnquire