Goran WitchDoc
ServiceNow Employee

EDIT: *The UI Page "CodeSearchExampleUse" mention below doesn't work in Istanbul release, there you need atm. go through the studio*

I have been supposed to write this post for months now, and finally I got the time to do it.

I doubt I'm the only one being in the position where I forgot where I wrote a specific piece of code or that you can see that something is changing the data, but you can't figure out how/where.

Lucky for us, ServiceNow has a solution for us, you just need to search a bit to find it. The solution is named "Code Search". This been around for a while and it pretty much lets you easy search for a piece of code in a lot of places. After read what I could find in the docs, I would guess this is made primary for the ServiceNow Studio and I'll come back to that in the end of this post.

so, here is how to find it:

Code Search itself is an application and you can find it by going to "System Applications->Applications" in the navigator.

find_real_file.png

Then you need to click on "downloads" and there it appears in the list. You can click on it to get some more information about it.

find_real_file.png

Looking around in the records it has, you can see that it got a UI page called "CodeSearchExampleUse", let's look at it.

find_real_file.png

You can see its got a endpoint, so lets click on it and see how it looks like.

find_real_file.png

Just check the box "Search All Applications" and fill in what you looking for and tada, it gives you the result.

find_real_file.png

Here you can see that for example there is 2 client scripts having "setValue" within them. It also give us the client script name and even at which row it can be found.

Atm. I can see that it searches through:

  • Approval Steps
  • Inbound Email Actions
  • Style
  • Installation Exists
  • Client Script
  • Validation Script
  • Scheduled Script Execution
  • Relationship
  • Macro
  • UI Page
  • AJAX Script
  • Transform Script
  • Notification
  • MID Server Script Include
  • Access Control
  • Map Page
  • Workflow Activity Definition
  • Knowledge Nav-ons
  • Schedule Item
  • Table Transform Map
  • UI Script
  • Business Rule
  • Dynamic Content
  • Email Template
  • BSM Map Actions
  • Processor
  • Script Include
  • UI Action
  • UI Policy
  • Widget
  • Script Action

So it's quite the list and a real nice help to find stuff.

But it's some clicks to get to the search page and sadly there isn't an application with modules done for this. But you can make your own.

This is what I have done:

find_real_file.png

I've made my own application with modules that I use often and I put CodeSearch as one module. The module looks like this:

find_real_file.png

And just to show you what I meant with it exists in studio, this is where you will find it:

find_real_file.png

So there you go. I hope this will help you in the search of code as it has done for me.

Take care,

Göran

Symfoni Logo Color Box.jpgadvocate.jpg

Comments
ServiceNow Employee
ServiceNow Employee

*Update*



This seem to not work like 100% in Istanbul release. In Helsinki I can't find any errors, but in Istanbul it wont give any search results for things in a business rule. Not unless you search inside Studio through the Code Search there is.



EDIT: Doesnt seem to find anything that isnt inside the code search application



//Göran


Mega Sage

Hi Goran,



Thank you !!



In my instance, i can see only 7 tables in "Search table"? do i need to change anything?


Tera Guru

I found an acceptable work-around for the time being. In the module's url arguments, if you point it to the studio and the sys id of one of your apps it will open the studio view in the current window. Then you can click 'Code Search' or 'Search' and progress as normal. You'll of course need to select 'Search in all applications'.


example:


put this in the 'arguments' field on the module (replace sys id here with sys id of an app in your environement)


/$studio.do?sysparm_transaction_scope=478b292e20723500418891d0c5c4036b&sysparm_nostack=true




find_real_file.png


ServiceNow Employee
ServiceNow Employee

Another quick way to search for code is to search the sys_metadata table (works on all versions of ServiceNow afaik):



find_real_file.png


Giga Sage

The shortcut doesn't has the links to the script which Studio provides. Correct ? Just double checking


Tera Guru

Correct



Thanks, Bryan


ServiceNow Employee
ServiceNow Employee

Love all the ideas coming up here to get it going in Istanbul 😃



/Göran


ServiceNow Employee
ServiceNow Employee

HI amaradiswamy,



Which release are you on?


Tera Expert

great thanks goranlundqvist DOC


Kilo Sage

I probably found the not working piece.


It looks like the checkbox is not set correctly and is always evaluated to false.



UI Page CodeSearchExampleUse - Client Script in line 14: !!$j("#sn_codesearch_search_all_scopes").attr("checked") -> false



Right now, I couldn ´t figure out why it is evaluated to false. ctomasi Do you have any idea?


find_real_file.png



As a workaround you can create a copy of the UI Page and set the param search_all_scopes to true.


Mega Sage

Looks like this is working in London again. They've changed the row 14 on the client script of that UI page to:

search_all_scopes : $j("#sn_codesearch_search_all_scopes").is(":checked")

Kilo Sage

I worked on an own solution which I put on the share today (it´s based on the same Rest API with a nicer interface): https://developer.servicenow.com/app.do#!/share/contents/4888545_ms_codesearch?t=PRODUCT_DETAILS

 

ServiceNow Employee
ServiceNow Employee

Nice, Probably since you can do "global apps" in studio, they had to change it back 🙂

Tera Guru

Ummm... yeah, like PERFECT!  Thank you, @sebastianreinmann !!!

Kilo Contributor

Thank you @Göran WitchDoctor Lundqvist 

Mega Sage

That's exactly what I do.

Tera Contributor

Cool!