- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 03:45 AM
Hi,
I am have a category widget which initially shows only limited number of categories. I have a button in the widget "View All". When the user clicks that button, the widget should refresh and show all the categories. Below is my code am using. Where am i doing wrong. ctomasi nathanfirth pradeepksharma
Server:
if(input){
data.catParam = $sp.getParameter("kb_category");
data.kb = $sp.getValue("kb_knowledge_base");
var cats1 = new GlideRecord("kb_category");
cats1.addQuery("parent_id", data.kb);
cats1.orderBy('label');
cats1.query();
while(cats1.next()){
data.categories.push({label: cats1.getDisplayValue("label"), value: cats1.getUniqueValue()});
}
}
Client:
$scope.seeAll = function()
{
c.server.get().then(function(r) {
c.data.categories = r.data.categories;
});
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 07:47 AM
i think we traced down the error.
it looks like c.server.update returns data it self. so you can directly do
c.data.categories = r.newItems;
see if this works.
(please mark helpful/like/correct if it helps)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 05:22 AM
Hi,
i dont see any difference between your if and else loop. make sure your logic is correct and code reflects that.
(please mark helpful/like/correct if it helps)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 05:28 AM
Hi Rushit,
My logic is working good. If and else are same because this widget used in two pages. It will behave accordingly. As of now my ELSE pasrt is working and fetching all my category records. But am doing correct in refreshing the data.categories in client script.? Kindly advice
My updated server code:
if(input){
data.catParam = $sp.getParameter("kb_category");
data.kb = $sp.getValue("kb_knowledge_base");
var cats1 = new GlideRecord("kb_category");
cats1.addQuery("parent_id", data.kb);
cats1.orderBy('label');
cats1.query();
while(cats1.next()){
data.categories.push({label: cats1.getDisplayValue("label"), value: cats1.getUniqueValue()});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 06:55 AM
difficult to tell from that..what does your code to show initial limited category look like?
also what you are doing when "view all" button is clicked?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 07:05 AM
I have a query run to show online 20 category initially. When the user click "View All". The widget should refresh and show all the categories. Below is the widget code
Server :
(function() {
data.catParam = $sp.getParameter("kb_category");
data.kb = $sp.getValue("kb_knowledge_base");
var cats = new GlideRecord("kb_category");
if (data.catParam){
cats.addQuery("parent_id", data.kb);
cats.addQuery("u_top_category","true");
cats.orderBy('label');
cats.setLimit(20);
cats.query();
}
else {
cats.addQuery("parent_id", data.kb);
cats.addQuery("u_top_category","true");
cats.orderBy('label');
cats.setLimit(20);
cats.query();
}
data.categories = [];
while (cats.next()) {
var articleCount = -1;
var kbCount = $sp.getKBCount(data.kb);
if (kbCount < 500) { // if more than 500 articles, don't iterate to get viewable counts
var arts = $sp.getKBCategoryArticles(cats.getUniqueValue());
articleCount = arts.length;
}
data.categories.push({label: cats.getDisplayValue("label"), value: cats.getUniqueValue(), count: articleCount});
}
if(input){
data.catParam = $sp.getParameter("kb_category");
data.kb = $sp.getValue("kb_knowledge_base");
var newItems = [];
var cats1 = new GlideRecord("kb_category");
cats1.addQuery("parent_id", data.kb);
cats1.orderBy('label');
cats1.query();
gs.log("Cats Length"+cats1.getRowCount());
while(cats1.next()){
data.newItems.push({label: cats1.getDisplayValue("label"), value: cats1.getUniqueValue()});
}
}
})();
Client :
function($location, $scope) {
var c = this;
//c.server.update();
this.getMaxShownLabel = function(maxEntries, totalCount) {
if (totalCount == c.data.maxCount)
return "${First [0] of more than [1]}".replace('[0]', maxEntries).replace('[1]', totalCount);
return "${First [0] of [1]}".replace('[0]', maxEntries).replace('[1]', totalCount);
};
$scope.seeAll = function()
{
c.server.update().then(function(r) {
c.data.categories = r.data.newItems;
});
};
}