SNOW-CAD Creating and customizing tables and data Practice Question
A developer writes a script to display the department name of the caller on a custom form. The script uses: gs.getUser().getDepartment().getName(). However, the script throws a null pointer exception for some users. Which is the most likely cause and solution?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Some users do not have a department assigned, and the script does not check for null
The NullPointerException suggests that getDepartment() returned null for users without a department. Option A is wrong because the script is syntactically correct. Option B is wrong because reference exists. Option C is wrong because department records exist.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The Department table is empty
Why it's wrong here
If the department table is empty, getDepartment() would return null, but the error is specifically for some users, not all.
- ✗
The script uses incorrect dot-walking syntax; use getValue('department') instead
Why it's wrong here
The dot-walking syntax is correct; gs.getUser().getDepartment().getName() is valid GlideRecord dot-walking.
- ✗
The user table does not have a department reference field
Why it's wrong here
The sys_user table has a department reference field by default.
- ✓
Some users do not have a department assigned, and the script does not check for null
Why this is correct
When getDepartment() returns null, calling getName() on null causes a NullPointerException. The solution is to add a null check before calling getName().
Go deeper
Related to this question
About these practice questions
This SNOW-CAD question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This SNOW-CAD practice question is part of Courseiva's free ServiceNow certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SNOW-CAD exam.