How to check any field reference/existence in Servicnow?

Virendra K
Kilo Sage

Hello,

There is one field "XYZ" where I want to inactivate it, but before doing that I want to make sure whether this field has been used anywhere in service-now scripting, table, BR, etc.

As I have not created this field so I am not aware of its use. How could I find out this ?

1 ACCEPTED SOLUTION

Shusovit
Mega Expert

Go to tables and columns module and check this option:




find_real_file.png



Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


View solution in original post

7 REPLIES 7

Please close this thread. then only this will be helpful for other community users.



Please mark my response as correct/Endorse so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.If you are viewing this from the community inbox you will not see the correct answer button.


If so, please review How to Mark Answers Correct From Inbox View




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

But does this work on OOB applications?

Dubz
Mega Sage

Hi Virendra,



Put the script below into a fix script or background script and set the search term to your field name and it will search the platform for any places where it is referenced.


If you put it in a fix script it'll give some orange alerts but you can ignore them. I claim no responsibility for this code, it was given to me by one of our implementation partners.




var term = "search, terms"; //use comma to separate terms


var useAndQuery = true; //search for term 1 and term 2. If false, it will look for term 1 or term 2.


var debug = false; //set this true if you want to troubleshoot the script.


var delimiter = ","; //if you want to split terms on something other than a comma




var globalScriptSearch = {




    search: null,


   


    delimiter: ",",


   


    out: ["\n"],


   


    debug: false,


   


    useAndQuery: true,    




    /* Main method that calls all the sub-methods.*/


    search: function(term, useAndQuery, debug, delimiter) {


          if (typeof debug != "undefined") this.debug = debug;


          if (typeof delimiter != "undefined") this.delimiter = delimiter;


          if (typeof useAndQuery != "undefined") this.useAndQuery = useAndQuery;


          if (typeof term != "string") {


                gs.print("GlobalScriptSearch - ERROR: must pass a valid search term to search");


                return false;


          }


          this.search = term;


          this._searchLocations();


          this._searchFieldTypes();


          this._searchWorkflow();


          gs.print(this.out.join("\n"));


          return true;


    },


   




    _searchLocations: function() {


          var locations = {


                "question": "default_value",


                "sys_trigger": "job_context",


                "sys_dictionary": "calculation",


                "sys_dictionary_override": "calculation",


                "sys_ui_macro": "xml",


                "sys_ui_page": "html",


                "sys_impex_entry": "default_value",


                "content_block_programmatic": "programmatic_content",


          }


          for (var location in locations) {


                this._searchLocation(location, locations[location]);


          }


    },


   




    _searchFieldTypes: function() {


          var fieldList = new GlideRecord("sys_dictionary");


          var fieldTypes = ["script_plain", "script", "email_script", "condition_string", "conditions"];


          var aq = null;


          for (var ic = 0; ic < fieldTypes.length; ic++) {


                if (aq == null)


                      aq = fieldList.addQuery("internal_type", fieldTypes[ic]);


                else


                      aq.addOrCondition("internal_type", fieldTypes[ic]);


          }


          this._searchFieldsNamedScript(aq);




          //exclude all field types that don't come from String


          var nonString = new GlideRecord("sys_glide_object");


          nonString.addQuery("scalar_type", "!=", "string");


          nonString.query();


          while (nonString.next()) {


                fieldList.addQuery("internal_type", "!=", nonString.name + "");


          }


          fieldList.addQuery("internal_type", "!=", "boolean");


          fieldList.query();


          while (fieldList.next()) {


                if (fieldList.name.indexOf("var__") >= 0)


                      continue;


                this._searchLocation(fieldList.name, fieldList.element);


          }


    },


   




    _searchFieldsNamedScript: function(addQuery) {


          addQuery.addOrCondition("element", "ENDSWITH", "script");


          addQuery.addOrCondition("element", "STARTSWITH", "script");


    },


   




    _searchWorkflow: function() {


          var allDocs = [];


          var tableName = 'sys_variable_value';


          var fieldName = 'value';


          var rec = new GlideRecord(tableName);


          rec.addQuery('document', 'wf_activity');


          var qc = rec.addQuery('variable.element', 'CONTAINS', 'script');


          qc.addOrCondition('variable.internal_type', 'CONTAINS', 'script');


          var terms = this.search.split(this.delimiter);


          for (var ib = 0; ib < terms.length; ib++) {


                if (this.useAndQuery) {


                      rec.addQuery(fieldName, 'CONTAINS', terms[ib]);


                } else {


                      if (ib == 0)


                            var aq = rec.addQuery(fieldName, "CONTAINS", terms[ib]);


                      else


                            aq.addOrCondition(fieldName, "CONTAINS", terms[ib]);


                }


          }


          this._addMatches(tableName, fieldName, rec);


    },


   




    _searchLocation: function(table, field) {


          var fieldName = field + "";


          var tableName = table + "";


          if (this.debug)


                gs.print("_searchLocation: " + tableName + " " + fieldName);


          var target = new GlideRecord(tableName);


          if (!target.isValid()) {


                gs.print("GlobalScriptSearch - ERRROR: " + tableName + " was an invalid table name (field: " + fieldName + ").");


                return;


          }


          var terms = this.search.split(this.delimiter);


          if (this.debug)


            gs.print("_searchLocation: terms.length " + terms.length);


          if (this.useAndQuery) {


                for (var ia = 0; ia < terms.length; ia++) {


                      target.addQuery(fieldName, "CONTAINS", terms[ia]);


                }


          } else {


                var aq;


                for (var ia = 0; ia < terms.length; ia++) {


                      if (ia == 0)


                            var aq = target.addQuery(fieldName, "CONTAINS", terms[ia]);


                      else


                            aq.addOrCondition(fieldName, "CONTAINS", terms[ia]);


                }


          }


          this._addMatches(tableName, fieldName, target);


    },






    _addMatches: function(tableName, fieldName, match) {


          try {


                match.query();


                if (match.getRowCount() < 1) return;


                var matchList = [];


                this.out.push("\n\n* Searching - " + tableName + "." + fieldName + " ***");


                while(match.next()) {


                      matchList.push(match.sys_id+"");


                      this.out.push(match.getClassDisplayValue() + " - " + match.getDisplayValue() + ": /" + tableName + ".do?sys_id=" + match.sys_id);


                }


                this.out.push("\n[All matches] /" + tableName + ".do?sysparm_query=sys_idIN" + matchList.join(","));


          } catch(e) {


                gs.print("GlobalScriptSearch - ERRROR: failure while trying to insert match " + e);


          }


    },


   


    type: 'GlobalScriptSearch'


}




globalScriptSearch.search(term, useAndQuery, debug, delimiter);