- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 03:26 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 04:01 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 03:41 AM
Hi Mike,
There is indeed a very easy way: ServiceNow Studio.
Select any Application (do not forget to switch back to your application once you are done with studio)
DO NOT forget to click search in all applications.
Please mark as CORRECT if this solves your query
Thanks,
DR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 04:09 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 04:16 AM
Have you checked using .indexOf('Keywords')>-1?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 04:56 AM
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:
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-term | Search for values that end with search-term. |
search-term% | Search for values that start with search-term. |
=search-term | Search for values that equal search-term. |
!*search-term | Search for values that do not contain search-term. |
!%search-term | Search for values that do not end with search-term. |
!=search-term | Search for values that do not equal search-term. |