Skip to tutorial content
Rate module Not yet rated

Scripts – Background

2 min read
On this page

In this lesson, you will learn:

  • What Scripts – Background is for
  • The parts of the Scripts – Background page
  • How to use it safely

1 A place to run a script now

Sometimes you want to run a quick server-side script, just once. Maybe to test some code, or to count records. Scripts – Background is the place. 🧪

Key term: Scripts – Background

A page where admins type and run server-side JavaScript right away. Find it at System Definition > Scripts – Background.

The Scripts - Background page. Marker 1: the script box, with a script that counts active P1 incidents and prints the count with gs.info. Marker 2: the scope menu, set to global. Marker 3: the Record for rollback checkbox. Marker 4: the Run script button. Marker 5: the output area, showing *** Script: Active P1 incidents: 3.
Figure 1. Type the script, pick the scope, run it, and read the output.

2 Parts of the page

Part What it does
Script box Where you type server-side JavaScript
in scope Which application scope the script runs in. Usually global
Record for rollback? Saves the changes so you can undo them later
Run script Runs the script right now
Output Shows messages from gs.info(), starting with *** Script:

3 A safe first script

This script only reads data. It doesn’t change anything.

var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('priority', 1);
gr.query();
gs.info('Active P1 incidents: ' + gr.getRowCount());

📝 Note: You need the admin role. On many instances you also need to elevate to the security_admin role first (user menu > Elevate role).

⚠️ Heads up: Scripts here run with full power, right away. One wrong line can change or delete thousands of records. Test in snwrdev, start with read-only scripts, and never experiment in production.

💡 Good to know: If you used Record for rollback, you can undo a script’s changes from the Script Execution History (the link appears after the run).

⭐ Remember: Scripts – Background = run server-side code now. Powerful, so test in dev first.

4 Let’s try it: count some records

  1. If needed, elevate to security_admin from your user menu.
  2. Open System Definition > Scripts – Background.
  3. Paste the script above. Keep scope global. Click Run script.
  4. Change priority to 2 and run it again. How many P2s are there?

5 Quick recap

  • Scripts – Background runs server-side scripts right away
  • Pick the scope, then click Run script
  • Output from gs.info() shows as *** Script:
  • Record for rollback lets you undo changes
  • Use it carefully, and never experiment in production

6 Check yourself

Think of your answer first. Then tap to check.

1 Does Scripts – Background run client side or server side? Show answer

Server side.

2 Which option lets you undo a script’s changes later? Show answer

Record for rollback.

3 Which role do you often need to elevate to first? Show answer

security_admin.

Nice work! You finished this lesson. 🎉

Was this lesson helpful?

Have a question or doubt?

Ask here and get help from instructors and fellow learners.

0 / 300

Only logged-in learners can post.