function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mshimmshim 

Knowledge [Unable to query for Featured articles]

I’m a developer that is working on the KnowledgeBase system (PKB2) and featured articles do not work. The out-of-the-box code has the featured articles query populating as below:

String q = '';
q += 'select ' +join(kavFields, ',')+ ' from KnowledgeArticleVersion';
q += ' where PublishStatus = \'' +pkb_Controller.DEFAULT_PUBLISH_STATUS+ '\' and Language = \'' +lang+ '\' and ArticleNumber in :anums’;

Which clearly will not work since you can’t have “in: anums” in a query string, so I fixed that part of it and ran the query again, but there is also a problem when trying to query “ArticleNumber” – it returns 0 in the list on the public knowledge site, but 1 (which is the correct size) when I’m querying it on the Development Console (as a System Admin)

Anyone run into this issue?

Bradley DelauneBradley Delaune
Hi mshim,
I don't have a ton of experience with the PKB2 package, but I may be able to help.  First, where are you seeing this code?  I don't believe you are correct saying
you can’t have “in: anums” in a query string
If "anums" is a set or list, you most certainly can have that as part of a query string.  Maybe the 1 article isn't in a published status?
I'll need more info to help you out.
mshimmshim
Hi Bradley, 

Thank you for the reply. "anums" is a list of string (Article_Number__c) taken from the PKB_Featured__c object. And the reason why I believe the "in: anums" statement doesn't work is because when I debug the query string, I get this:


[DEBUG-PKB CONTROLLER] initFromListOfArticleNumbers query
====select FirstPublishedDate,LastModifiedDate,Language,Id,ArticleNumber,UrlName,PublishStatus,LastPublishedDate,Title,KnowledgeArticleId,Summary from KnowledgeArticleVersion where PublishStatus = 'online' and Language = 'en_US' and ArticleNumber in: anums order by LastPublishedDate desc=====

This returns 0 rows. 

And when I hardcode the article number and I debug it:

[DEBUG-PKB CONTROLLER] initFromListOfArticleNumbers query
====select FirstPublishedDate,LastModifiedDate,Language,Id,ArticleNumber,UrlName,PublishStatus,LastPublishedDate,Title,KnowledgeArticleId,Summary from KnowledgeArticleVersion where PublishStatus = 'online' and Language = 'en_US' and ArticleNumber = '000014363' order by LastPublishedDate desc=====

This still returns 0 rows. 

The featured article is published and Language is en_US. I can get that article when my query does not have the ArticleNumber filter. (And yes, I know for sure the ArticleNumber 000014363 exists in the system because I can get the result by using the Developer Console as a System Admin).
Bradley DelauneBradley Delaune
mshim,
Try using the debug console to query exactly for article number '000014363' and have it return the Language and Publish Status.  Let me know what it says and we can see how the query can be improved.
mshimmshim
Hi Bradley, 

My post above has the debug query that shows the Publish Status and Language. Here it is again:

[DEBUG-PKB CONTROLLER] initFromListOfArticleNumbers query
====select FirstPublishedDate,LastModifiedDate,Language,Id,ArticleNumber,UrlName,PublishStatus,LastPublishedDate,Title,KnowledgeArticleId,Summary from KnowledgeArticleVersion where PublishStatus = 'online' and Language = 'en_US' and ArticleNumber = '000014363' order by LastPublishedDate desc=====

Publish Status is 'online' and Language is 'en_US'


Bradley DelauneBradley Delaune
mshim,
It's likely that your query is wrong.  You need to check the Article you are trying to pull (I'm assuming its number 000014363).  Make sure the PublishStatus and Language of that article is actually 'online' and 'en_US'.  YOu may be getting no results because the PublishStatus is 'Online' instead of 'online'.
mshimmshim
As I said before the query is unlikely to be wrong as I pasted this query into the Development console and it gives me the result I want. It shows me the 1 article that exists in the system with those filters.

Online & online is the same thing.