Issue with Roles and the Kb_knowledge table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 05:18 PM
Hi Everyone,
I am having an issue with what I believe to be a role issue surrounding the kb_knowledge table. I have a script querying this table but the script only works for knowledge.managers. I have tried digging through a few things, but I cannot seem to find the resolution. Anyways, I would like this query to work for any end user.
So to start from the top I have a catalog item that has 3 categories. Once these 3 categories have been selected, I then have a custom widget that displays a knowledge article connected with the 3 categories.
This is done by utilizing a client catalog script, as well as a client callable script that tells the widget what to display.
Codes below -
Client Callable:
var KB_Data_Utils = Class.create();
KB_Data_Utils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getKBID: function() {
var category = this.getParameter('sysparm_cat');
var subcategory = this.getParameter('sysparm_sub_cat');
var issue = this.getParameter('sysparm_issue');
var kbArticle = new GlideRecord('kb_knowledge');
kbArticle.addQuery('u_knowledge_base', "General");
kbArticle.addQuery('category', category);
kbArticle.addQuery('u_subcategory', subcategory);
kbArticle.addQuery('u_issue', issue);
kbArticle.query();
if (kbArticle.next()) {
return kbArticle.number + '';
}
return '';
},
type: 'KB_Data_Utils'
});
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading && newValue) {
var category = g_form.getValue('category');
var subcategory = g_form.getValue('subcategory');
var kbGa = new GlideAjax('KB_Data_Utils');
kbGa.addParam('sysparm_name', 'getKBID');
kbGa.addParam('sysparm_cat', category);
kbGa.addParam('sysparm_sub_cat', subcategory);
kbGa.addParam('sysparm_issue', newValue);
kbGa.getXMLAnswer(populateKBID);
}
function populateKBID(answer) {
if (answer) {
g_form.setValue('u_knowledge_article1', answer);
} else {
g_form.setValue('u_knowledge_article1', '');
}
}
Widget Server Script:
(function() {
// Only run the below after the client controller calls this. Reason: Catalog item loads quicker & the script below requires the variable_name loaded in the page
data.isArticle = false;
var article_num = data.kbNumber;
if(input) {
var article = new GlideRecord('kb_knowledge'); // Initiate a glide record object (knowledge article table)
article.addQuery('number', input.kbNumber); // The KB number corresponds to the default value set in this variable of the record producer
article.addQuery('workflow_state', 'published');// The KB article should be in the published state to be shown to end-users
article.query(); // Execute the query
if(article.next()) { // If an article is found, show the article
data.articleTitle = article.getDisplayValue('short_description').toString(); // Capture the title of the article
data.articleHTML = article.text.toString().replace('<![CDATA[ ', '').replace(' ]]>', ''); // Capture & clean the body HTML of the article
data.isArticle = true;
} else if(gs.nil(article_num)){
data.articleTitle = '<p> No KB Article found </p>';
data.articleHTML = " <h3> No KB Article Available </h3><br> Please continue to submit a ticket by selecting <b> KB Article prompted me to submit ticket </b> below";}
else { // If an article is not found, display the below message
data.articleHTML = '<p>Article ' + data.kbNumber + ' missing or out-dated. Please contact support.<p>';
}
}
})();
As mentioned above, if you have the knowledge.manager role (or perhaps something else that role encompasses) than the preview of the KB Article works. But if you're a generic end user with 0 roles. No Article is displayed, only the elseif statement is displayed in the widget.
If you have any tips or tricks in locating where i need to make adjustments, that would be greatly appreciated!!
thanks,
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 09:41 PM - edited 06-06-2023 09:41 PM
Update - The visibility is actually dependent on the "ITIL" role and not knowledge.manager role.