SNOW-CAD User Interface Development Practice Question
Exhibit
function onChange(control, oldValue, newValue, isLoading, isTemplate) {\n if (isLoading) return;\n if (newValue == '1') {\n g_form.hideField('field2');\n }\n}Refer to the exhibit. A developer wrote this client script to hide a field when another field changes to '1'. However, the script throws a JavaScript error. What is the most likely cause?
⚠ Common exam trap
ServiceNow often tests the distinction between valid and invalid g_form methods, and the trap here is that candidates may assume `hideField` is a real method because it sounds intuitive, without knowing the exact API names like `setDisplay` or `setVisible`.
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
✓
hideField is not a valid method; the correct method is setDisplay or setVisible.
`hideField` is not a valid client-side method in ServiceNow. The correct methods to control field visibility in client scripts are `setDisplay` (to show/hide a field) or `setVisible` (to show/hide a field and its label). Using an undefined method like `hideField` will throw a JavaScript error because the GlideForm (g_form) API does not include it.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
hideField is not a valid method; the correct method is setDisplay or setVisible.
Why this is correct
Correct: g_form.setDisplay('field2', false) or g_form.setVisible('field2', false) should be used.
- ✗
hideField is a server-side method and cannot be used in client scripts.
Why it's wrong here
Wrong: hideField is not even a server-side method; it's not part of the API.
- ✗
The developer should use showFieldMsg to hide the field.
Why it's wrong here
Wrong: showFieldMsg displays a message, it does not hide fields.
- ✗
The function signature is incorrect for an onChange client script.
Why it's wrong here
Wrong: The signature is correct: function onChange(control, oldValue, newValue, isLoading, isTemplate).
Go deeper
Related to this question
About these practice questions
Courseiva writes every SNOW-CAD question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.