|
| 1 | +const USAGE_COUNT_CONFIG = [ |
| 2 | + { "table": "sys_dictionary", "field": "reference", "title": "Dictionary" }, |
| 3 | + { "table": "item_option_new", "field": "reference", "title": "Variables" }, |
| 4 | + { "table": "sys_script", "field": "collection", "title": "Business Rules" }, |
| 5 | + { "table": "sys_script_client", "field": "table", "title": "Client Scripts" }, |
| 6 | + { "table": "sys_dictionary", "field": "name", "title": "Dictionary Entries" }, |
| 7 | + { "table": "sys_dictionary_override", "field": "name", "title": "Dictionary Overrides" }, |
| 8 | + // { "table": "sysevent_email_action", "field": "collection ", "title": "Notifications", "query": "" }, |
| 9 | + { "table": "sys_ui_action", "field": "table", "title": "UI Actions" }, |
| 10 | + { "table": "sys_security_acl", "field": "name", "title": "ACL", "query": "STARTSWITH" }, |
| 11 | + { "table": "sys_ui_policy", "field": "table", "title": "UI Policies", }, |
| 12 | + { "table": "sys_data_policy2", "field": "model_table", "title": "Data Policy" }, |
| 13 | + { "table": "sys_ui_style", "field": "name", "title": "Styles" }, |
| 14 | + { "table": "sysrule_view", "field": "table", "title": "View Rules" }, |
| 15 | + { "table": "wf_workflow", "field": "table", "title": "Workflows" }, |
| 16 | + { "table": "sys_hub_flow", "field": "sys_id", "title": "Flows", "query": "", "query_field": "sys_id" }, |
| 17 | + { "table": "sys_script_include", "field": "script", "title": "Script Include", 'query': 'CONTAINS'} |
| 18 | +]; |
| 19 | + |
| 20 | +// get list of fields to query from the table |
| 21 | +// grab any fields which are listed as query_fields in the usage config, and add name and label. |
| 22 | +var selectFields = USAGE_COUNT_CONFIG.map(function (_obj) { |
| 23 | + return _obj.query_field; |
| 24 | +}).filter(Boolean); |
| 25 | + |
| 26 | +selectFields.push('name'); |
| 27 | +selectFields.push('label'); |
| 28 | + |
| 29 | +var gqTables = new global.GlideQuery('sys_db_object') |
| 30 | + .where('name', 'STARTSWITH', 'u_') |
| 31 | + // don't want m2m tables |
| 32 | + .where('name', 'NOT LIKE', 'm2m') |
| 33 | + // don't want tables extended from Import Set Row or Query Builder Results |
| 34 | + // apologies for the hard-coded sys_ids, they'll never change, right? |
| 35 | + .where('super_class', 'NOT IN', ['88d993c3b4232110320f8dc279c8042b', '897b97c7b4632110320f8dc279c80489']) |
| 36 | + .select(selectFields) |
| 37 | + .map(function (_table) { |
| 38 | + var references = {}; |
| 39 | + _table.references = references; |
| 40 | + |
| 41 | + USAGE_COUNT_CONFIG.forEach(function (_usageConfig) { |
| 42 | + var query_type = _usageConfig['query'] ? _usageConfig['query'] : "="; |
| 43 | + var query_field = _usageConfig['query_field'] ? _usageConfig['query_field'] : 'name'; |
| 44 | + |
| 45 | + var gqUsageCount = new global.GlideQuery(_usageConfig.table) |
| 46 | + .where(_usageConfig.field, query_type, _table[query_field]) |
| 47 | + .count(); |
| 48 | + |
| 49 | + references[_usageConfig.title] = gqUsageCount; |
| 50 | + }) |
| 51 | + delete _table["sys_id"]; // get rid of the sys_id field |
| 52 | + |
| 53 | + return _table; |
| 54 | + }) |
| 55 | + .reduce(function (arr, e) { arr.push(e); return arr; }, []); |
| 56 | + |
| 57 | +gs.info(JSON.stringify(gqTables, '', 3)) |
| 58 | + |
| 59 | + |
| 60 | + |
0 commit comments