Article [3] : Understanding ServiceNow Scripting: Learning Through Practice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2025 07:01 AM - last edited a week ago
The purpose of learning is not just to get the right answer, but to explore and understand things deeply. While preparing for the CAD certification, I came across a few interesting scripting topics. I decided to explore them and wanted to share what I learned
Debugging method used in the server-side scripting in a scoped application
- gs.error()
- gs.debug()
- gs.info()
For Scoped Applications:
Method | Works? | Explanation |
gs.info() | ✅Yes | Recommended and supported |
gs.debug() | ✅Yes | Debug-level logging |
gs.error() | ✅Yes | Error logging |
Validation:
Now checking for debug and debuglog option:
Validation:
-----------------------------------------------------------------------------------------------------------------------------------
How to identify methods that can be used in a Business Rule:
- gs.hasRole()
- g_user.hasRole()
- gs.hasRoleExactly()
- g_user.hasRoleExactly()
Trick: for Business Rule (server side) = gs. and Client side = g_
Method | Works in Business Rule? | Explanation |
gs.hasRole('admin') | ✅Yes | Available for server side |
gs.hasRoleExactly('admin') | ❌No | Not available on server side |
g_user.hasRole('admin') | ❌No | Client-side only (UI). |
g_user.hasRoleExactly('admin') | ❌No | Client-side only (UI). |
Validation:
----------------------------------------------------------------------------------------------------------------------------------------
Which are valid Methods that prints a message?
- g_form.showFieldMessage()
- g_form.addInfoMessage()
- g_form.addInfoMsg()
- g_form.showFieldMsg()
Answer: g_form.addInfoMessage()
Method | Valid | Notes |
g_form.addInfoMessage() | ✅Yes | ✔️Correct answer |
g_form.showFieldMessage() | ❌No | throws “not a function” |
g_form.addInfoMsg() | ❌No | throws “not a function” |
g_form.showFieldMsg() | ✅Yes | Inline field messages |
The question is straight forward, but check the syntax difference for Field and Info Message, there is subtle change which can cause confusion if question is reversed asked about field message.
----------------------------------------------------------------------------------------------------------------------------------------------
Important ServiceNow document links:
If you found this article helpful, please give it a thumbs-up. If you notice any discrepancy in the article, feel free to correct it, I am always happy to improve. Also, if you have faced tricky ServiceNow scripting questions in the CAD exam you can share it here so others can benefit too.
Thanks and Regards,
Mohamed Zakir
- 5,091 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2026 02:23 PM - last edited a week ago
Just cleared CAD certification (30-12-2025), More Important topics discussed below
Which a Business Rule returns the sys_id of the currently logged in user. (confusing option, easily identified with thorough practice)
- g_form.getUserID()
- gs.getUserSysID()
- gs.getUserID()
- g_form.getUserSysID()
Method | Valid API? | Notes |
gs.getUserID() | ✅ | Correct answer |
gs.getUserSysID() | ❌ | Not a real GlideSystem function/API |
g_form.getUserID() | ✅ | Works only in Client Side |
g_form.getUserSysID() | ❌ | Not a real function/API |
Validation: Answer: gs.getUserID()
-----------------------------------------------------------------------------------------------------------------------------------------------
Following methods are useful in Access Control scripts? (Important topic from E-book)
- g_user.hasRole() and current.isNewRecord()
- gs.hasRole() and current.isNewRecord()
- g_user.hasRole() and current.isNew()
- gs.getUserRole() and current.isNew()
Answer: gs.hasRole() and current.isNewRecord()
Reason: Explained in CAD E-book, for Yokohama version of book you can find -> Module 5: Controlling Access. Topic: Access Control Scripting