Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 01:34 AM
I would like to write a script that pushes IDs of a specific knowledge bases into an array, taking into consideration that we can have a category, subcategory, subsubcategory etc, anyone can give me leads? The idea is to make some field mandatory on the category dependinding on what knowledge base it is inherited from.
Cheers.
Solved! Go to Solution.
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 04:17 AM
Okay, try something like this, and let me know if it works for you.
var categoryGR = new GlideRecord('kb_category');
categoryGR.addQuery('parent_id', 'a7e8a78bff0221009b20ffffffffff17'); // sys ID of knowledge base you want to list
categoryGR.query();
var arrayCategoryValues = [];
while(categoryGR.next()){
arrayCategoryValues.push(categoryGR.getValue('label'));
findSubcategory(categoryGR.getUniqueValue());
}
if (arrayCategoryValues.length > 0){
for (var i=0; i< arrayCategoryValues.length; i++){
gs.info('Category label: ' + arrayCategoryValues[i]);
}
}
else{
gs.info('No data found');
}
function findSubcategory(categoryID){
var subCategoryGR = new GlideRecord('kb_category');
subCategoryGR.addQuery('parent_id', categoryID);
subCategoryGR.query();
if (subCategoryGR.hasNext()){
while(subCategoryGR.next()){
arrayCategoryValues.push(subCategoryGR.getValue('label'));
findSubcategory(subCategoryGR.getUniqueValue());
}
}
}
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 04:43 AM
Thank you for your kind words!