Searching for scripts containing certain strings

Mike I2
Giga Guru

Hi, 

I'm sure there's a very simple way to to this, although I'm having a mental block! How would I search for scripts containing a specific string. For example, looking for scripts containing "method('ref_field',sys_id)" syntax?

Thanks in advance

Mike

1 ACCEPTED SOLUTION

Mike I2
Giga Guru

Thanks for your replies on this. I ended up writing a background script using a regular expression to find what I was looking for, as the search criteria I needed to use was something like "setValue('<something>',<something>)"

Something like:

 

var regex = new RegExp(/(?:setValue\(\')(?:.+)(?:\'\)\,\ )(?:.+)(?:\))/);
var gr = new GlideRecord('sys_script_client');
gr.addQuery('IR_OR_QUERY , regex);
gr.query();
while(gr.next()) {
gs.print(gr.name);
}

It wasn't perfect; I had to add an encoded query to remove things like where scripts don't include "clearOptions" to remove any client scripts that are setting the values of choice lists, for example. It got most of what I needed though. 

 

 

View solution in original post

7 REPLIES 7

Community Alums
Not applicable

Hi Mike,

 

There is indeed a very easy way: ServiceNow Studio.

find_real_file.png

Select any Application (do not forget to switch back to your application once you are done with studio)

find_real_file.png

find_real_file.png

find_real_file.png

DO NOT forget to click search in all applications.

Please mark as CORRECT if this solves your query

Thanks,
DR

Mike I2
Giga Guru

Hi. Thanks for taking time to reply. It was actually the search syntax I needed help with. If I want to search for, as an example, client scripts where setValue was using the syntax of "setValue('ref_field', sys_id')", I can't remember how to find that using wildcards.

Have you checked using .indexOf('Keywords')>-1?

Community Alums
Not applicable

Hi Mike,

Do you need these results in a script? If not, studio still seems like the way to go. For example look at this search similar to your requirement:

find_real_file.png

Or you could use either ".indexOf('search string') > -1" or bring the script field in your list view and use wildcards:

*search-term

%search-term%

Search for values that contain search-term.
%search-termSearch for values that end with search-term.
search-term%Search for values that start with search-term.
=search-termSearch for values that equal search-term.
!*search-termSearch for values that do not contain search-term.
!%search-termSearch for values that do not end with search-term.
!=search-termSearch for values that do not equal search-term.