Need one page to search all scripts - IDEAS?

troyp
Giga Contributor

I can't be alone. You know it is out there. A chunk of script buried somewhere in the system. You've seen it, you may have even modified it. But where, oh where has it gone?

Can someone help me figure this out. I'm not sure how to implement it: complex filter, ui page, etc.

Check this out?
https://demo10.service-now.com/sys_dictionary_list.do?sysparm_query=internal_type%3Dscript%5EORinter...

There are 111 fields that are either type script or script_plain. That's a lot of places to LOOK.

I'd like to have a single page that has a search box that searches all those fields using "CONTAINS", then returns the table, name, script, active, updated columns.

Sure I know we can use the list views for common script locations. I've used it for business rules, client scripts, and ui actions separately.

Here is an example searching for business rules with "getDisplayValue":
https://demo10.service-now.com/sys_script_list.do?sysparm_query=scriptLIKEgetDisplayValue

Would that need to be a ui page with jelly to loop over the table types, then include the list view of each result? Any thoughts?

I'd like to create the module and put it in the system definition application on the left-nav visible to administrators.

8 REPLIES 8

xMTinkerer
Giga Expert

 

EDIT: Or, check out the second google result which shows the Code Searcher in studio:
https://community.servicenow.com/community?id=community_blog&sys_id=136caea1dbd0dbc01dcaf3231f96198a

I needed to search the scripts, but I don't really need end users to do it, so I took your query and stuffed it into a GlideRecord and created a script. I'm not totally sure if this is exhaustive or not, but it should suffice for most needs. 

 

queryText = 'getDisplayValue';

var dict = new GlideRecord( 'sys_dictionary' );

dict.addQuery( 'internal_type=script^ORinternal_type=script_plain^nameNOT LIKEvar__' );
dict.query();

while( dict.next() ) {
	//gs.info( 'table: ' + dict.name + '. element: ' + dict.element );

	rec = new GlideRecord( dict.name );
	rec.addQuery( dict.element, 'CONTAINS', queryText );

	rec.query();
	while( rec.next() ) {
		gs.info( '    Found: table: ' + dict.name + '(' + rec.getClassDisplayValue() + ', ' + rec.getDisplayValue() + '). sys_id: ' + rec.sys_id + '. element: ' + dict.element );
	}
	
}

If anyone has tweaks post a reply. 

 

There are 5 projects on Share that do Code Search

https://developer.servicenow.com/connect.do#!/share/contents?page=1&keyword=code%20search


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

B_35
Tera Contributor

In Studio, in the top right, there is a thing called "Code Search".  If you type in the phrase you are looking for there, it will search all of your code files, at least if you are in an application.  Maybe that could be used somehow.

B_35
Tera Contributor

Actually, this tool even has an option to "Search all applications", so I think this might do what you are looking for

Code search in top right of studio:

find_real_file.png

Search dialogue once you click "Code Search":

find_real_file.png