Code Search
code_searchSearch a ServiceNow instance for scripts, business rules, and includes matching a term, returning record names, tables, fields, and line numbers with context.
Instructions
Search for code across a ServiceNow instance using the Code Search API. Finds matching scripts, business rules, script includes, and other code artifacts across the platform. Results include the record name, table, field, and matching line numbers with context.
Code Search works through Search Groups, which define sets of tables and fields to search. There is typically a default search group. Use list_code_search_groups to discover available groups, and list_code_search_tables to see which tables a group covers.
Key use cases:
Find scripts that reference a specific API, table, or pattern
Locate business rules, script includes, or UI scripts containing specific logic
Verify whether code has been deployed to an instance
Search within a specific application scope or table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| term | Yes | The search term to find in code. Searches across script fields in the tables defined by the search group. | |
| limit | No | Maximum number of results to return. | |
| table | No | Specific table to search within (e.g., "sys_script_include"). Requires `search_group` to also be specified. Use `list_code_search_tables` to see available tables for a group. | |
| instance | No | The ServiceNow instance auth alias (e.g., "myinstance", "prod"). If not provided, falls back to the SN_AUTH_ALIAS environment variable. | |
| current_app | No | Application scope to limit results to (e.g., "x_myapp"). When set, only results from this application scope are returned. Automatically sets search_all_scopes to false. | |
| search_group | No | The search group NAME to scope the search (e.g., "Default Code Search Group"). If omitted, the instance's default search group is used. Use `list_code_search_groups` to discover available groups. | |
| search_all_scopes | No | When false, limits results to files within the scope specified by `current_app`. Defaults to true (search all scopes). |