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

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....

find_real_file.png

... here we go:

4) right click the breadcrumbs and select "Copy query"

find_real_file.png

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:

https://docs.servicenow.com/bundle/jakarta-application-development/page/use/common-ui-elements/refer...

Have fun and build an App.

Thanks for marking as correct/helpful.

BR

Dirk

 

 

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. 

 

 

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