Skip to content

Commit d466943

Browse files
authored
Create customTableUsage.js
1 parent 6218cd5 commit d466943

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
];
18+
19+
// get list of fields to query from the table
20+
// grab any fields which are listed as query_fields in the usage config, and add name and label.
21+
var selectFields = USAGE_COUNT_CONFIG.map(function (_obj) {
22+
return _obj.query_field;
23+
}).filter(Boolean);
24+
selectFields.push('name');
25+
selectFields.push('label');
26+
27+
var gqTables = new global.GlideQuery('sys_db_object')
28+
.where('name', 'STARTSWITH', 'u_')
29+
// don't want m2m tables
30+
.where('name', 'NOT LIKE', 'm2m')
31+
// don't want tables extended from Import Set Row or Query Builder Results
32+
// apologies for the hard-coded sys_ids, they'll never change, right?
33+
.where('super_class', 'NOT IN', ['88d993c3b4232110320f8dc279c8042b', '897b97c7b4632110320f8dc279c80489'])
34+
.select(selectFields)
35+
.map(function (_table) {
36+
var references = {};
37+
_table.references = references;
38+
39+
USAGE_COUNT_CONFIG.forEach(function (_usageConfig) {
40+
var query_type = _usageConfig['query'] ? _usageConfig['query'] : "=";
41+
var query_field = _usageConfig['query_field'] ? _usageConfig['query_field'] : 'name';
42+
43+
var gqUsageCount = new global.GlideQuery(_usageConfig.table)
44+
.where(_usageConfig.field, query_type, _table[query_field])
45+
.count();
46+
47+
references[_usageConfig.title] = gqUsageCount;
48+
})
49+
delete _table["sys_id"]; // get rid of the sys_id field
50+
51+
return _table;
52+
})
53+
.reduce(function (arr, e) { arr.push(e); return arr; }, []);
54+
55+
gs.info(JSON.stringify(gqTables, '', 3))

0 commit comments

Comments
 (0)