rahul-garg/generategliderecordquery icon
public
Published on 4/15/2025
Generate GlideRecord Query

Generate GlideRecord Query

Prompts
Generate GlideRecord Query
Generate GlideRecord Query
## Generate GlideRecord Query

**Goal:** Create an efficient server-side GlideRecord query.

**Table:** `{table_name}`
**Query Purpose:** {Describe what records you need to find. e.g., "Find all active Incident records assigned to the 'Software' assignment group that were created in the last 7 days."}
**Fields Required:** {List specific field sys_names needed. e.g., "`sys_id`, `number`, `short_description`, `caller_id`"}

**Request:**
Generate a server-side ServiceNow script using `GlideRecord` to perform this query efficiently.
- Use `addQuery()`, `addEncodedQuery()`, or `addActiveQuery()` appropriately.
- Select only the necessary fields (`setLimit()`, specific `get*` methods if only one record needed).
- Include basic iteration logic (e.g., `while (gr.next()) {}`).
- Follow ServiceNow performance best practices for queries.