- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 12:32 PM
Hello,
I was wondering if there is a way to create a knowledge article that would update each time a catalog item has been loaded into the production environment. It would need to capture active-only catalog items with the fields as name, short description, description, and owner and pricing.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 02:58 PM
Hi Brett,
You would need a business rule that executes when new records are added to sc_cat_item. That business rule could then query sc_cat_item for active records, add them to an array with the content you want, and add it to the knowledge record.
I haven't tested, but something like this might get you started:
var catItemInfo = [];
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
catItemInfo.push(gr.name.toString())
}
var textToAdd = '';
for (var i = 0; i < catItemInfo.length; i++) {
textToAdd += catItemInfo[i] + '<br>';
}
var ka = new GlideRecord('kb_knowledge');
ka.addQuery('sys_id', 'id_of_your_article');
ka.query();
if (ka.next()) {
ka.text = textToAdd;
ka.update();
}
If you want to test this in Scripts - Background, you can run this:
var catItemInfo = [];
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
catItemInfo.push(gr.name.toString() + ' ' + gr.short_description.toString())
}
var textToAdd = '';
for (var i = 0; i < catItemInfo.length; i++) {
textToAdd += catItemInfo[i] + '\n';
}
gs.info(textToAdd);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 02:58 PM
Hi Brett,
You would need a business rule that executes when new records are added to sc_cat_item. That business rule could then query sc_cat_item for active records, add them to an array with the content you want, and add it to the knowledge record.
I haven't tested, but something like this might get you started:
var catItemInfo = [];
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
catItemInfo.push(gr.name.toString())
}
var textToAdd = '';
for (var i = 0; i < catItemInfo.length; i++) {
textToAdd += catItemInfo[i] + '<br>';
}
var ka = new GlideRecord('kb_knowledge');
ka.addQuery('sys_id', 'id_of_your_article');
ka.query();
if (ka.next()) {
ka.text = textToAdd;
ka.update();
}
If you want to test this in Scripts - Background, you can run this:
var catItemInfo = [];
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
catItemInfo.push(gr.name.toString() + ' ' + gr.short_description.toString())
}
var textToAdd = '';
for (var i = 0; i < catItemInfo.length; i++) {
textToAdd += catItemInfo[i] + '\n';
}
gs.info(textToAdd);