Need help with widget to display kb article content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2022 09:57 PM
Hi everyone,
I am working on an widget to display a knowledge article on a catalog item based on a variable on the form. There are multiple KB article depended on the value of this variable. I have stored the KB numbers in a system property and fetch those in the server script and display the KB article body on the HTML template.
This is the client controller to watch the variable on the catalog item and update it on the server-
function($scope,$rootScope,$sce) {
/* widget controller */
var c = this;
c.data.showWidget=false;
$scope.$watch(function () {
return $scope.page.g_form.getValue('api_dummy_variable');
},function (value) {
c.data.action=value;
if (c.data.action!=""){
c.server.get({action:c.data.action}).then(function(response){});
}
});
}
This is the server script-
(function() {
var gr1= new GlideRecord('kb_knowledge');
if (input.action=="r_change"){
gr1.addQuery("number="+gs.getProperty("api_knowledge_article").split(",")[0].split(":")[1]+"^workflow_state=published"); //fetching the kb article number from a property
gr1.query();
if (gr1.next()){
data.text=new global.KBViewModel().getArticleContentBySysId(gr1.getUniqueValue());
}
}
else if (input.action=="w_change"){
gr1.addQuery("number="+gs.getProperty("api_knowledge_article").split(",")[1].split(":")[1]+"^workflow_state=published"); //fetching the kb article number from a property
gr1.query();
if (gr1.next()){
data.text=new global.KBViewModel().getArticleContentBySysId(gr1.getUniqueValue());
}
}
})();
This is the HTML template-
<div>
<h2>Knowledge Article:</h2>
<div ng-if="!data.direct" class="kb_article" ng-class="{'knowledge-wiki-text' : data.articleType == 'wiki'}"
ng-bind-html="::data.text" style="overflow-x:auto;"></div>
</div>
There's nothing being displayed on the form. If I remove the if condition from the server script, it seems to work but that is not the intended functionality.
Any idea how can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2022 10:09 PM
Can you do an alert in your client controller for c.data.action and check if that is returning "w_change" or "r_change".
function (value) {
c.data.action=value;
alert(c.data.action);
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2022 10:17 PM
Yes it does. I do get the value as I change the variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2022 10:24 PM
can you change gr1.addQuery() to gr1.addEncodedQuery() and try.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2022 10:52 PM
Okay, trying this out.