Code Search
code_searchSearch ServiceNow code artifacts like scripts and business rules by term, with filters for table, application scope, and search group. Returns matching records with line numbers.
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 |
|---|---|---|---|
| instance | No | The ServiceNow instance auth alias (e.g., "myinstance", "prod"). If not provided, falls back to the SN_AUTH_ALIAS environment variable. | |
| term | Yes | The search term to find in code. Searches across script fields in the tables defined by the search group. | |
| 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. | |
| 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. | |
| 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_all_scopes | No | When false, limits results to files within the scope specified by `current_app`. Defaults to true (search all scopes). | |
| limit | No | Maximum number of results to return. |