The Code Search
The Code Search feature, which has existed in the product documentation for ServiceNow as far back as the Geneva release, is a useful development tool that could easily be overlooked. In this article, we will introduce you to the Code Search and help guide you to its somewhat peculiar hiding place within the platform.
At the time of writing, this tool is only available from within the ServiceNow Studio, an environment typically used for scoped application development. However, the Code Search has relevance to all ServiceNow development and can be utilized in contexts wholly unrelated to scoped applications.
Accessing the Tool
To access the code search:
1) Type “Studio” into the the navigator and access the module that appears under the System Applications menu. (Note: The studio is available as a baseline feature of ServiceNow.)
2) You will be presented with a menu requesting that you select an application or create a new one. You may select an application if it’s relevant to your search, but this dialog can be bypassed by using the keyboard shortcut Ctrl + Shift + F (in Windows) to open the Code Search directly. If you choose to select an application, you can then use the aforementioned keyboard shortcut or the link at the top right to open the search.
3) Once the Code Search is open, you will be presented with a search box, a drop-down menu that allows you to select a specific table to search on, and a checkbox that allows you to extend the search to all applications, including global. It’s the checkbox that is most essential: It allows you to search the instance at large for relevant code.
From this dialog, you can search a robust number of tables within the instance for appearances of a string of your choice. The Code Search will find the provided string in any of the following tables:
- Script Includes
- Business Rules
- Client Scripts
- UI Policies
- Access Controls
- UI Actions
- Inbound Email Actions
- Email Templates
- Map Pages
- Scheduled Script Executions
- Script Actions
- Transform Maps
- UI Macros
- UI Pages
- UI Scripts
When I use the above procedure to search for references to “change_task” in a baseline instance, I get 68 search results, sorted by table context. Expanding an item in the resulting accordion menu shows me the name of each record where the string appears and, within each of these entries, I can see the context within the record where the string appears!
Though making broad changes to application behavior is usually a sensitive endeavor, it is often necessary. The Code Search feature can help with identifying the full scope of a set of necessary updates. It also helps significantly cut down the time necessary to seek out calls to script includes across an eclectic set of contexts. The tool is useful enough that Pathways has submitted an enhancement request with ServiceNow to make the Code Search available as a module outside of the Studio entirely, as we believe this will make access to the tool more convenient. If you agree, we encourage you to submit an enhancement request of your own!
The number of applications of this feature are many, and we hope you find a way to use it to improve your productivity while developing within the ServiceNow platform.