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
hiteshwar marnihiteshwar marni 

Knowledge Articles

I'm querying some fields in knowledgearticle version , but I need to qeury another field from articletype__kav also.how to do it?
As there is no relation between knowledgeArticleversion and articletype__kav.


Thanks
Ashish DevAshish Dev
I think you can do query based on KnowledgeAriticleId, more help can be provided if you put code you are using.
hiteshwar marnihiteshwar marni

User-added image
In the above image all the fields from knowledgearticleversion object are passed throught restapi.
But requirement is another field from howto__kav (description__c) object should also be sent 
hiteshwar marnihiteshwar marni


@RestResource(urlMapping='/mhcknw/*')

global class knowledgeApi{
           @HttpGet
    global static list<wrapperclass> findrecords(){
  

       list<wrapperclass> wrapperlist;

    RestRequest request = RestContext.request;
         RestResponse res = RestContext.response;
        string kmId = request.requestURI.substring(
          request.requestURI.lastIndexOf('/')+1);
          system.debug('######'+kmid);
    
    list<KnowledgeArticleVersion> ka=[SELECT Id,KnowledgeArticleId,Language,PublishStatus,Summary,Title FROM KnowledgeArticleVersion WHERE PublishStatus = 'online' AND Language = 'en_US' and KnowledgeArticleId =:kmid];
        system.debug('@@@@@@'+ka);

   list<hitesh31__Test_Art__kav> htak= [SELECT ArticleNumber,ArticleType,Id,KnowledgeArticleId,Language,PublishStatus,Summary FROM hitesh31__Test_Art__kav WHERE Language = 'en_US' AND PublishStatus = 'online' AND KnowledgeArticleId =:kmid];
     system.debug('*******'+htak);
     for(KnowledgeArticleVersion ka1:ka){
         for(hitesh31__Test_Art__kav htak1:htak){
             wrapperlist.add(new wrapperclass(Ka1,htak1));
    system.debug('&&&&&&&'+wrapperlist);


         }
     }

        return wrapperlist;
    
    
    } 
    
    global class wrapperclass{
    public KnowledgeArticleVersion kversion;
    public hitesh31__Test_Art__kav katype;
        public wrapperclass(KnowledgeArticleVersion kn,hitesh31__Test_Art__kav k ){
           kversion=kn;
            katype=k;
    }

}
}

In the above class i'm able to get records into the above two queries.but when i' calling this api from workbench it throwing nullpointer exception.I think there is some problem in wrapperlist.i'm not able to debug that, but records are getting into the query's.