[Article] Search throughout the entire instance — all fields from all records.

Szymon6
Tera Contributor

A simple script that allows you to search across all fields of all update-tracked records for a specific phrase. It outputs matching entries with their URLs. To use it, simply set PHRASE variable and execute it in any server side environment (e.g. background script), within the global scope.

 

var PHRASE = 'your phrase';

(function executeQuery() {
    var count = 0;
    var results = '';
    new GlideQuery('sys_dictionary')
        .where('attributes', 'CONTAINS', 'update_synch=true')
        .aggregate('COUNT', 'name')
        .groupBy('name')
        .select()
        .forEach(function(dictionary) {
            var table = dictionary.group.name;
            new GlideQuery(table)
                .select(global.j2js(GlideTableDescriptor(table).getActiveFieldNames()))
                .forEach(function(r) {
                    var data = (Object.keys(r).map(function(k) {
                        return r[k];
                    }).join(', '));
                    if (data.includes(PHRASE)) {
                        results += '\n\n' + r.sys_name + '\n';
                        results += 'URL: /' + table + '.do?sys_id=' + r.sys_id + '\n';
                        count++;
                    }
                });
        });
    gs.info('\n\nFound ' + count + ' results for phrase \'' + PHRASE + '\'' + results);
})();

 

 

Example use:

If you ever wondered how many records (on the fresh instance) contain the phrase "dogs” — there are two of them.

Script output:

carbon2.png

First result:

socialscreenshots-1_8_2025, 1_28_34 PM.png

Second result:

socialscreenshots-1_8_2025, 1_29_39 PM.png

Obviously, the best use for this script is any kind of development-related investigation — i.e. when you come across a value embedded in a plain text / a part of the script, and need to track down where it's coming from & where else it's being used. 

 

Note: Make sure you are using at least Utah release.

 

Linkedin

 

0 REPLIES 0