
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Thursday
Introduction
Employee Center product OOB provides curated experience for users as part of unified taxonomy
As part of EC, EC pro unified taxonomy implementation design phase, it's required to find out all your content ( Knowledge Article Categories and SC categories) category which go beyond 3 level deep.
As best practice, it's recommended to configure your taxonomy below 3 levels deep so that user's get to their content with minimum number of clicks.
There is no OOB API available which can return how deep these content categories are present on your instances.
I have created this article to share a script which provides this data to you which can help you in your Employee Center implementations.
Solution
You can run this script on your instance which will generate CSV and attach these files to your user records.
(function() {
var MAX_STEPS = 200;
function processCategories(table, parentField, fileName) {
var all = {};
var gr = new GlideRecord(table);
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
all[gr.getUniqueValue()] = {
parent: gr.getValue(parentField),
label: gr.getDisplayValue() || gr.getValue('name') || gr.getUniqueValue()
};
}
var results = [];
for (var sysId in all) {
var visited = {};
var pathParts = [];
var current = sysId;
var steps = 0;
while (current && all[current] && !visited[current]) {
visited[current] = true;
pathParts.push(all[current].label);
current = all[current].parent;
steps++;
if (steps > MAX_STEPS) {
gs.warn('Exceeded max parent traversal steps for category: ' + sysId + ' in table ' + table);
break;
}
}
var depth = pathParts.length; // root-only = 1, child = 2, etc.
if (depth > 3) {
var fullPath = pathParts.slice().reverse().join(' > ');
results.push({
sys_id: sysId,
label: all[sysId].label,
depth: depth,
path: fullPath
});
}
}
if (results.length === 0) {
gs.info('No active ' + table + ' records found deeper than 3 levels.');
return;
}
// Build CSV content (include table column so both files can be merged if desired)
var csv = "Table,Sys ID,Label,Depth,Full Path\n";
for (var i = 0; i < results.length; i++) {
var r = results[i];
csv += '"' + table + '","' + r.sys_id + '","' + r.label.replace(/"/g, '""') + '","' + r.depth + '","' + r.path.replace(/"/g, '""') + '"\n';
}
// Attach CSV to current user record
var userId = gs.getUserID();
var grUser = new GlideRecord('sys_user');
if (grUser.get(userId)) {
var sa = new GlideSysAttachment();
sa.write(grUser, fileName, "text/csv", csv);
gs.info("CSV file for " + table + " attached to your user record: " + fileName);
} else {
gs.warn("Could not find user record to attach CSV for table: " + table);
}
}
// kb_category uses parent_id
processCategories('kb_category', 'parent_id', 'kb_categories_deeper_than_3_levels.csv');
// sc_category uses parent
processCategories('sc_category', 'parent', 'sc_categories_deeper_than_3_levels.csv');
})();