Article [3] : Understanding ServiceNow Scripting: Learning Through CAD Questions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 2 weeks 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 questions. Instead of just getting the answers, I decided to explore them and wanted to share what I learned
1) What debugging method you use in the server side scripting in a scoped application?
- gs.addInfoMessage()
- gs.debuglog()
- gs.info
- gs.log
Answer: 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 |
gs.log() | ⚠️Avoid | Not recommended in scoped app |
gs.debuglog() | ❌No | Function does not exist |
It is easy to assume the answer is gs.debuglog() as it sounds like the right choice. So instead of guessing, let us run each option in Background Scripts inside a scoped app and see what happens.
Validation:
Now checking for debug and debuglog option:
Validation:
-----------------------------------------------------------------------------------------------------------------------------------
2) Which of the following methods can be used in a Business Rule?
- gs.hasRole()
- g_user.hasRole()
- gs.hasRoleExactly()
- g_user.hasRoleExactly()
Answer: gs.hasRole()
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:
----------------------------------------------------------------------------------------------------------------------------------------
3) Which of the following methods prints a message on a blue background to the top of the current form by default?
- 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 answers, 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,
Mohammed Zakir
- 1,128 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Just cleared CAD certification (30-12-2025 ), From above questions posted Q1, Q2, Q3 all appeared in exam not exact wordings but with slight variations.
Here are few I faced and remember:
04) In a Business Rule, which one of the following returns the sys_id of the currently logged in user?
- A. g_form.getUserID()
- B. gs.getUserSysID()
- C. gs.getUserID()
- D. g_form.getUserSysID()
Answer: gs.getUserID()
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:
-----------------------------------------------------------------------------------------------------------------------------------------------
05) Which of the following methods are useful in Access Control scripts?
- A. g_user.hasRole() and current.isNewRecord()
- B. gs.hasRole() and current.isNewRecord()
- C. g_user.hasRole() and current.isNew()
- D. 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
