Article [3] : Understanding ServiceNow Scripting: Learning Through CAD Questions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours 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