How Client Scripts Get Server Data in ServiceNow | GlideAjax & g_scratchpad
ServiceNow with Kalyan
0:00 / 0:00
How Client Scripts Get Server Data in ServiceNow | GlideAjax & g_scratchpad
201 просмотр · 3 недели назад
ServiceNow with Kalyan
344 подписчика
201 просмотр · 3 недели назад
🚀 SERVICE NOW CLIENT SCRIPTS — PART 2 | g_scratchpad & GlideAjax
In Part 1, we learned the four types of ServiceNow Client Scripts — onLoad, onChange, onSubmit and onCellEdit.
But there's an important question:
👉 What happens when your Client Script needs information from the ServiceNow server?
That's exactly what we're going to solve in Part 2.
In this video, we'll learn g_scratchpad and GlideAjax with practical, real-world ServiceNow examples and understand the difference between server-to-client communication and client-to-server-to-client communication.
🔥 WHAT YOU'LL LEARN
✅ What is g_scratchpad in ServiceNow?
✅ What is GlideAjax in ServiceNow?
✅ Client-side vs Server-side scripting
✅ How Client Scripts communicate with the server
✅ Display Business Rules and g_scratchpad
✅ Script Includes and GlideAjax
✅ Client Callable Script Includes
✅ sysparm_name
✅ Passing parameters using addParam()
✅ getXMLAnswer()
✅ Asynchronous GlideAjax
✅ Returning data from a Script Include
✅ Working with JSON responses
✅ JSON.stringify() and JSON.parse()
✅ Reference fields and sys_ids
✅ GlideAjax best practices
✅ When to use g_scratchpad vs GlideAjax
💻 LIVE DEMONSTRATIONS
🔹 Demo 1 — g_scratchpad
Current User → Department
We'll use a Display Business Rule to prepare server-side information and make it available to an onLoad Client Script.
🔹 Demo 2 — g_scratchpad
Incident Caller → Manager
We'll retrieve Caller information on form load using g_scratchpad.
🔹 Demo 3 — GlideAjax
Incident Caller → Department
When the Caller changes, we'll dynamically retrieve the Caller's Department from the server using:
Client Script → GlideAjax → Script Include → sys_user → Response
🔹 Demo 4 — Developer-Level GlideAjax
Caller → Manager + Department + VIP Status
Instead of making multiple server calls, we'll return multiple pieces of information through one GlideAjax request using JSON.
🧠 g_scratchpad vs GlideAjax
One of the most important concepts in this video:
g_scratchpad
Server → Client
Use it when you know the information is required when the form loads.
GlideAjax
Client → Server → Client
Use it when the Client Script needs to dynamically request information from the server.
You'll learn exactly when to use each approach instead of simply memorizing the syntax.
🔥 IMPORTANT GLIDEAJAX CONCEPTS
We'll break down the GlideAjax process step-by-step:
Client Script
↓
GlideAjax
↓
Script Include
↓
Server / Database
↓
Response
↓
Client Script
↓
Update Form
You'll also learn why asynchronous GlideAjax should generally be preferred and why unnecessary server calls can negatively affect the user experience.
👨💻 FOR SERVICE NOW DEVELOPERS
This video is especially useful if you're:
✔ Learning ServiceNow Development
✔ Preparing for ServiceNow Developer interviews
✔ Working with Client Scripts
✔ Learning GlideAjax
✔ Learning Script Includes
✔ Moving from ServiceNow Administration to Development
✔ Working with Incident, Problem and Change forms
✔ Preparing for real-world ServiceNow development projects
📚 PART 1 → PART 2
Part 1
ServiceNow Client Scripts
We covered:
onLoad
onChange
onSubmit
onCellEdit
Catalog Client Scripts
Real-world Incident, Problem and Change use cases
Part 2
g_scratchpad & GlideAjax
We now take Client Scripts to the next level by learning how to retrieve server-side information.
Coming Next 🚀
Part 3 — UI Policy vs Client Script
We'll take real-world requirements and answer one of the most important questions for a ServiceNow Developer:
"Should I use a UI Policy or a Client Script?"
🎯 KEY TOPICS COVERED
ServiceNow Client Scripts | ServiceNow GlideAjax | GlideAjax Tutorial | g_scratchpad ServiceNow | ServiceNow Script Include | Client Callable Script Include | ServiceNow onChange Client Script | ServiceNow Client to Server | ServiceNow Server to Client | ServiceNow JavaScript | ServiceNow Development | ServiceNow Developer Tutorial | ServiceNow ITSM
🚀 LEARN • BUILD • GROW
If you're building your career as a ServiceNow Developer, subscribe to ServiceNow with Kalyan for practical ServiceNow development tutorials, real-world use cases, scripting, ITSM and developer-focused content.
👍 Like the video if it helped you.
💬 Comment your ServiceNow questions below.
🔔 Subscribe for the next part of the series.
#ServiceNow #ServiceNowDeveloper #GlideAjax #g_scratchpad #ServiceNowClientScripts #ServiceNowTutorial #ServiceNowDevelopment #ScriptInclude #ServiceNowScripting #ITSM