Courseiva
Application development using ServiceNow StudiohardMultiple ChoiceObjective-mapped

SNOW-CAD Practice Question: Application development using ServiceNow Studio

Exhibit

var gr = new GlideRecord('incident');
gr.addQuery('state', 1);
gr.query();
while(gr.next()) {
    gr.setValue('priority', 2);
    gr.update();
}

Refer to the exhibit. What is the primary issue with this script if it is intended to update all incidents in state 'New' (state=1) to priority 2?

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

The script will cause an infinite loop.

The primary issue is that calling gr.update() inside the while loop on the same GlideRecord object causes an infinite loop. When a business rule or trigger runs on update and re-queries the same set of records, gr.next() may keep returning true as newly updated records might still satisfy the query condition. Option A is incorrect because setValue syntax is correct. Option B is incorrect as next() iterates correctly. Option D is a possible secondary effect but not the primary issue.

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 script will not update any records because of a syntax error in setValue.

    Why it's wrong here

    setValue syntax is correct.

  • The script will update only the first record because next() is used incorrectly.

    Why it's wrong here

    next() is used correctly in a while loop.

  • The script will cause an infinite loop.

    Why this is correct

    Updating the same record while iterating over it can trigger conditions that requery the record, leading to an infinite loop.

  • The script will update records but may cause performance issues.

    Why it's wrong here

    Performance issues are secondary; the loop risk is more critical.

About these practice questions

One of 481 original SNOW-CAD practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.