- 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 05:06 AM
HI
You can teach yourself on how the syntax is, by using the Classic UI, like this:
1) Open the List, where you want to search for a code part
(see screenshot below for "Client Scripts" (1))
2) expand the Filter Conditions and add the search criteria for the "Script" field (2) m- see below
3) Run the Filter to add the condition in the breadcrumbs above (3)
read on below screenshot....
... here we go:
4) right click the breadcrumbs and select "Copy query"
5) now you have your "Encoded" query in the clipboard, which is in my case:
sys_class_name=sys_script_client^scriptLIKEsetValue('ref_field', sys_id)
This string can be used in a GlideRecord as "encoded Query".
For more details you can find the syntax in the ServiceNow Docs Online:
Have fun and build an App.
Thanks for marking as correct/helpful.
BR
Dirk
- 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
05-08-2020 07:18 AM
Hi
Thanks for clarification and your information.
Now, as your problem is solved, you can feel free to give some honor and mark the best received answer as correct, and close this thread. That will help to donate the writers here. Thanks a lot.
BR
Dirk