We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Pradeep Sharma
ServiceNow Employee

ServiceNow has developed a utility called "code search" which helps to search a code both within and outside of your application. This is helpful whenever you're troubleshooting or just trying to understand how something works. Code search is built into the ServiceNow Studio IDE interface to make developers life easier. Search can be easily applied without navigating to the platform UI by applying additional filters using Code Search. Code search is offered in the Geneva release onwards. I will walk you through an example of how to find a particular line of script/fields and where it is being used in the system

Example of how to use code search

Let's assume as part of my troubleshooting, I want to investigate what all scripts are triggered against a field for ex: close_notes which set the field to be mandatory. Here are the steps to be followed.

  1. On your instance navigate to System Applications>Studio
  2. Click on open Studio tab.

    Studio servicenow.jpg

  3. Now select one of the applications from the list (for example, Now application)

    code search application.jpg

  4. Now on upper right corner, you will see the "Code search" button.

    code search servicenow.png

  5. Click on Code Search.
  6. Enter the search for ex: close_notes.
  7. Now you have the option to either select a table to search from or search in all application.
  8. Select one of those options and hit search button.
  9. The output result will be the name of the script(hyperlink) with code line number in case a match is found.

    output result.jpg

As you can see, we have all of the scripts which are triggered against the field close_notes. In this particular case, it's most likely a client script/UI action/UI Policy which is responsible for the mandatory operation. Now I can go through all the scripts found to understand the behavior further.

Tables included in code search scanning:

Below is the list of tables on which scan is performed whenever a user enters a keyword to search for. For ex: In the above case we have searched for a field "close_notes".

  • Access Control
  • Business Rule
  • Client Script
  • Email Template
  • Inbound Email Action
  • Map Page
  • Notification
  • Processor
  • Relationship
  • Scheduled Script Execution
  • Script Action
  • Script Include
  • Style
  • Table Transform Map
  • UI Action
  • UI Macro
  • UI Page
  • UI Policy
  • UI Script

Please note the scan will be across global and scoped applications.

Code Search presents a powerful tool to developers. This is really helpful to find a particular script during active development in their instance. This allows the developer to search scripts across the platform, rather than doing the limited search on the individual table by applying a filter i.e business rules, client script, UI scripts, etc.

For more information on code search see:

Is there a way to make Studio's Code Search into a favorite or module?

What's New in Geneva for Developers?

26 Comments
Chuck Tomasi
Tera Patron

Hi Nia,



I did some checking/testing with the developer. Sadly, this table was put in for Istanbul, but the code is still doing a hard-coded search (ie. the table is ignored.) We can get the sp_widget table in the hard coded search list for Jakarta because it's a low risk incremental change, but we cannot convert to using the table at this point of the development cycle. That will have to wait until the K release. Sorry for the bad news.


Nia McCash
Mega Sage

No problem, Chuck.   Thanks for testing and verifying, and for updating me.   I appreciate all your help with improving the ServiceNow product.   Looking forward to SP code search being available in future releases!


joost2
Kilo Expert

It seems this only works for scoped applications. Can I use this to search scripts in global scope?


Chuck Tomasi
Tera Patron

Hi Joost,



Yes, you can use it to search all apps when you check the checkbox. You just cannot go in to Studio unless you have a scoped app. For that, I keep a "dummy" scoped app with just a name. When you start Studio select Start from scratch, give it a scope name, and now you can use the global search.


find_real_file.png


find_real_file.png


Pradeep Sharma
ServiceNow Employee

Hello Joost,



You are right. As chuck mentioned an app creation is mandatory to get in to search across all application.


Please let us know if you have any questions.


ettawilson
Giga Sage

Chuck, great idea for the "dummy" scoped app.   Sometimes I'll forget I'm in a working scoped app after I do a code search.



--Etta


Chuck Tomasi
Tera Patron

Hi Etta,



That's why I always show the application picker in my header.



find_real_file.png


AbdulNow
Tera Guru

This is so useful .. thanks for sharing

Sumit35
Tera Contributor

Hi Pradeep,

Its a wonderful article.

Small Help. Could you please let me know how to search in workflow activity script ?

 

Thanks,

Sumit

Subhash7
Giga Contributor
You may try this...
 
1) In the Navigator filter box, type sys_variable_value.list 
2) Click on the Filter wizard icon to create a custom filter
--- Table (document) is wf_activity AND
--- Variable.Column Name contains script' OR 
------ Variable.Type.Name contains 'script' AND
--- Value contains [whatever you are searching for]