Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

How to retrieve knowledge base articles and its attachments to Power Pages?

Posted on by 560
Hi,
     I have been working on the retrieving knowledge base article along with its attachments. I can be able to fetch the knowledge article content, but I could not be able to fetch its attachments. I have used fetch xml to accomplish this.
 
    For fetching attachments, I have tried to fetch the attachments of knowledge article from annotations table by filtering the objecttypecode eq 'knowledgearticle'. I need to get the base64 content of the attachment so that i can add that as a downloadable file in the portal. The filter will be like below.

https://<orgnamexyz123>.crm.dynamics.com/api/data/v9.2/annotations?$filter=objecttypecode eq 'knowledgearticle'
 
But I couldn't get results, and it returns an empty array. Are there any configurations behind this to fetch the attachment value from the D365 CRM Web API.

Any help or suggestions or other workaround on this would be much appreciated.
 
 
 
Thanks,
Tamilarasu Arunachalam
  • Suggested answer
    Sachin Jadhav Profile Picture
    Sachin Jadhav 131 on at
    How to retrieve knowledge base articles and its attachments to Power Pages?
    Hi,
     
    • Attachments added on Knowledge article(knowledgearticle) are stored in entity msdyn_kbattachment 
    • The relationship between knowledgearticle and msdyn_kbattachment is M:M (msdyn_msdyn_kbattachment_knowledgearticle) 
    • The actual file content that is the base 64 file itself is then stored in fileattachment table with objecttypecode and objectid pointing to msdyn_kbattachment table
     
    So if you have knowledgearticleid for knowledgearticle table, you can retrieve related attachments as follows.
     
    Fetch Query:-
     
    <fetch>
      <entity name="knowledgearticle">
        <attribute name="knowledgearticleid" />
        <filter>
          <condition attribute="knowledgearticleid" operator="eq" value="32b90f18-abf7-ea11-a815-000d3a1b14a2" />
        </filter>
        <link-entity name="msdyn_msdyn_kbattachment_knowledgearticle" from="knowledgearticleid" to="knowledgearticleid" intersect="true">
          <link-entity name="msdyn_kbattachment" from="msdyn_kbattachmentid" to="msdyn_kbattachmentid" alias="ka">
            <attribute name="msdyn_filename" />
            <attribute name="msdyn_filetype" />
            <attribute name="msdyn_filesize" />
            <link-entity name="fileattachment" from="fileattachmentid" to="msdyn_fileattachment" link-type="outer" alias="fa">
              <attribute name="body" />
            </link-entity>
          </link-entity>
        </link-entity>
      </entity>
    </fetch>
     
    ODATA 4.0 (WebAPI equivalent query):-
     
    https://<orgid>.crm8.dynamics.com/api/data/v9.2/knowledgearticles?$select=knowledgearticleid&$expand=msdyn_msdyn_kbattachment_knowledgearticle($select=msdyn_filename,msdyn_filetype,msdyn_filesize;$expand=msdyn_fileattachment($select=body))&$filter=(knowledgearticleid eq 32b90f18-abf7-ea11-a815-000d3a1b14a2) and (msdyn_msdyn_kbattachment_knowledgearticle/any(o1:(o1/msdyn_kbattachmentid ne null)))
     
     
    If this answers your question, please accept the same
  • Suggested answer
    Muhammad.Affan Profile Picture
    Muhammad.Affan 4,442 on at
    How to retrieve knowledge base articles and its attachments to Power Pages?
    Hi There,

    Refer to these links: 
    https://learn.microsoft.com/en-us/dynamics365/customer-service/administer/set-up-knowledge-management-embedded-knowledge-search#update-knowledge-article-attachments-for-portal

    https://community.dynamics.com/forums/thread/details/?threadid=c66cee9f-a99b-4ebd-be11-6e4959d9c4c9


    Finally, once your issue is resolved and my suggested answer has helped, please do not forget to click Yes under "Did this answer your question?" to close this thread.

    Thanks
    Affan
    Follow my channel related to Dynamics 365:  https://www.youtube.com/@AffansDynamicsJourney
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans