Scripting
Scripting in ServiceNow
There are two types of scripting in ServiceNow.
- Client Side
- Server Side
What is Client Side?
- OnChange Client Script
- OnLoad Client Side Script
- OnCellEdit Client Side Script
- OnSubmit Client Side Script
What is Server Side Scripting?
Types of Server-Side Scripts
1. Business Rules
Think of a business rule as a silent worker sitting inside the database. Every time someone saves, updates, or deletes a record, this worker wakes up and checks if it needs to do something. You get to decide whether it acts before the data is saved, right after it is saved, or quietly in the background without making the user wait. Imagine a student submitting an assignment — the moment they hit submit, a business rule can automatically stamp the submission time, notify the teacher, and update the grade book, all without the student doing anything extra.
2. Script Includes
Imagine you have a recipe that you use in many different dishes. Instead of writing that recipe again and again in every dish, you write it once and simply refer to it whenever needed. That is exactly what a Script Include does. It is a box of ready-made server-side code that sits on the shelf until someone calls it. Business rules, scheduled jobs, and even browser-side scripts can all reach into that box and use the same logic without anyone having to rewrite it.
3. Scheduled Jobs
A scheduled job is like setting an alarm on your phone, except instead of waking you up, it wakes up a script and tells it to get to work. You decide the time — maybe every night at midnight, every Monday morning, or the first day of every month. The script then runs on its own without anyone clicking a button. For example, every night it might scan all open tickets, find the ones that have been sitting untouched for a week, and automatically send a reminder to the assigned person.
4. Workflow and Flow Designer Scripts
When a process in your organization involves multiple steps, multiple people, and multiple decisions, a workflow holds it all together. Scripts inside a workflow run at specific points in that journey. For example, when a new employee joins a company, the workflow moves through steps — creating an account, assigning a laptop, sending a welcome email — and at each step, a script quietly does its job in the background, connecting all the pieces together without anyone having to manually trigger each one.
5. Scripted REST APIs
Sometimes systems outside ServiceNow need to talk to it — maybe a mobile app, a third-party tool, or another company's software. A Scripted REST API is like a reception desk that handles those incoming conversations. The outside system knocks on the door by sending a request, the script at the reception desk reads that request, does whatever work is needed inside ServiceNow, and then politely sends back an answer. The outside system never gets direct access to the database — it only gets what the script decides to share.
GlideRecord — The Key to the Database
If server-side scripting is a library, GlideRecord is the librarian. It knows where every record lives, can fetch exactly what you need, and can add, change, or remove records on your behalf. You tell the librarian which section to go to — meaning which table — give it some filters to narrow the search, and it brings back the matching records one by one for you to work with. Without GlideRecord, server-side scripts would have no way to read or write data, making it the single most important tool in all of ServiceNow development.
How Server-Side is Different from Client-Side
Picture a restaurant. The client script is everything the customer sees and experiences at the table — the menu, the waiter taking the order, the presentation of the food. The server-side script is everything happening in the kitchen — the chef cooking, the ingredients being prepared, the recipes being followed. The customer never sees the kitchen, but everything that comes to the table depends on what happens there. Client scripts make the experience look and feel good. Server-side scripts make sure the right data is prepared, processed, and delivered correctly behind the scenes

