- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
✨ Why Use Database Views?
✅ Combine data from multiple tables into a single virtual table without duplicating data.
✅ Avoid heavy nested GlideRecord queries in scripts.
✅ Enable reporting and list views directly on joined data.
✅ Improve query performance dramatically.
⚡ When Should You Use Database Views?
-
Need to build reports involving multiple tables (e.g., Incidents with user info from sys_user and assignment group details).
-
Need to create a list view combining custom data across apps.
-
Need a simplified source for Performance Analytics.
💥 How to Set It Up
1️⃣ Create a Database View
-
Go to System Definition > Database Views.
-
Click New, define the main table, and add other tables as joined tables (INNER JOIN or LEFT JOIN).
2️⃣ Define Join Conditions
-
Specify how tables link, e.g.:
incident.caller_id = sys_user.sys_id
-
You can use multiple conditions and aliases.
3️⃣ Create Database View Table
-
Once saved, a new "view" table becomes available. You can report on it just like a normal table!
4️⃣ Use GlideAggregate for Super-Fast Queries
var ga = new GlideAggregate('incident_user_view'); // Your database view name
ga.addAggregate('COUNT');
ga.addQuery('u_location', 'New York');
ga.query();
if (ga.next()) {
var count = ga.getAggregate('COUNT');
gs.info('Total incidents for NY: ' + count);
}
✅ Avoids nested loops.
✅ Extremely fast — all joins handled at the DB layer.
⚡ Pro Tip:
Use views carefully! Too many heavy joins or missing indexed fields can slow them down. Always test in sub-prod first.
✅ Why This Matters
-
💥 Massive performance gains on complex data reports.
-
💡 Cleaner, more maintainable code — no more nested GlideRecords.
-
📊 Easier and more powerful analytics and dashboards.
🔥 By combining Database Views and GlideAggregate, you unlock a whole new level of data efficiency in ServiceNow — taking your reporting and automation to the next level!
💬 Have you tried replacing nested GlideRecord loops with views yet? If not, this is your sign! 🚀✨
Mark 👍 Helpful if you find my response worthy based on the impact.
- 544 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.